@{
    ViewData["Title"] = "班组管理";
}

@section Styles {
    <style>
        /* 页面整体样式 - 简约大气企业级 */
        body {
            background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
            font-family: 'Microsoft YaHei', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            margin: 0;
            padding: 0;
        }

        /* 主容器 */
        .layui-fluid {
            padding: 24px;
            background: transparent;
        }

        /* 卡片样式 */
        .layui-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            border-radius: 16px;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
            border: 1px solid rgba(255, 255, 255, 0.2);
            overflow: hidden;
            margin-bottom: 24px;
        }

        /* 卡片头部 */
        .layui-card-header {
            background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
            color: white;
            padding: 24px 32px;
            border-bottom: none;
            position: relative;
            overflow: hidden;
        }

        .layui-card-header::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.1) 50%, transparent 70%);
            animation: shimmer 3s ease-in-out infinite;
        }

        .layui-card-header h3 {
            margin: 0;
            font-size: 20px;
            font-weight: 600;
            position: relative;
            z-index: 2;
        }

        /* 卡片内容 */
        .layui-card-body {
            padding: 32px;
            background: white;
        }

        /* 搜索区域 */
        .search-area {
            background: #f8fafc;
            border-radius: 12px;
            padding: 24px;
            margin-bottom: 24px;
            border: 1px solid #e5e7eb;
        }

        .search-form {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 20px;
            align-items: end;
        }

        .layui-form-item {
            margin-bottom: 0;
        }

        .layui-form-label {
            font-weight: 500;
            color: #374151;
            width: auto;
            padding: 0 0 8px 0;
            font-size: 14px;
        }

        .layui-input-block {
            margin-left: 0;
        }

        .layui-input,
        .layui-select {
            border: 2px solid #e5e7eb;
            border-radius: 8px;
            padding: 12px 16px;
            font-size: 14px;
            transition: all 0.2s ease;
            background: white;
            color: #374151;
        }

        .layui-input:focus,
        .layui-select:focus {
            border-color: #3b82f6;
            box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
            outline: none;
        }

        /* 按钮样式 */
        .layui-btn {
            border-radius: 8px;
            padding: 10px 20px;
            font-weight: 500;
            font-size: 14px;
            transition: all 0.2s ease;
            border: none;
            text-align: center;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 6px;
            min-width: 100px;
            position: relative;
            overflow: hidden;
        }

        .layui-btn::before {
            content: '';
            position: absolute;
            top: 0;
            left: -100%;
            width: 100%;
            height: 100%;
            background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
            transition: left 0.3s ease;
        }

        .layui-btn:hover::before {
            left: 100%;
        }

        .layui-btn-normal {
            background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
            color: white;
        }

        .layui-btn-normal:hover {
            transform: translateY(-1px);
            box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
        }

        .layui-btn-warm {
            background: linear-gradient(135deg, #ea580c 0%, #f97316 100%);
            color: white;
        }

        .layui-btn-warm:hover {
            transform: translateY(-1px);
            box-shadow: 0 4px 12px rgba(249, 115, 22, 0.3);
        }

        .layui-btn-danger {
            background: linear-gradient(135deg, #dc2626 0%, #ef4444 100%);
            color: white;
        }

        .layui-btn-danger:hover {
            transform: translateY(-1px);
            box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
        }

        .layui-btn-primary {
            background: #f3f4f6;
            color: #374151;
            border: 2px solid #e5e7eb;
        }

        .layui-btn-primary:hover {
            background: #e5e7eb;
            border-color: #d1d5db;
            transform: translateY(-1px);
        }

        /* 搜索按钮区域 */
        .search-buttons {
            display: flex;
            gap: 12px;
            flex-wrap: wrap;
            margin-top: 20px;
        }

        /* 表格样式 */
        .layui-table {
            border-radius: 12px;
            overflow: hidden;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
            border: 1px solid #e5e7eb;
        }

        .layui-table thead tr {
            background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
            color: white;
        }

        .layui-table thead th {
            border: none;
            padding: 16px 12px;
            font-weight: 600;
            font-size: 14px;
            text-align: center;
        }

        .layui-table tbody tr {
            transition: all 0.2s ease;
            border-bottom: 1px solid #f3f4f6;
        }

        .layui-table tbody tr:hover {
            background: #f8fafc;
            transform: translateY(-1px);
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        }

        .layui-table tbody td {
            padding: 16px 12px;
            border: none;
            font-size: 14px;
            color: #374151;
            text-align: center;
        }

        /* 班组类型标签 */
        .team-type-tag {
            display: inline-block;
            padding: 4px 12px;
            border-radius: 20px;
            font-size: 12px;
            font-weight: 600;
            color: white;
        }

        .team-type-warehouse {
            background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
        }

        .team-type-assembly {
            background: linear-gradient(135deg, #ea580c 0%, #f97316 100%);
        }

        .team-type-machining {
            background: linear-gradient(135deg, #dc2626 0%, #ef4444 100%);
        }

        .team-type-injection {
            background: linear-gradient(135deg, #059669 0%, #10b981 100%);
        }

        /* 分页样式 */
        .layui-laypage {
            text-align: center;
            margin-top: 24px;
        }

        .layui-laypage a,
        .layui-laypage span {
            border-radius: 6px;
            margin: 0 3px;
            transition: all 0.2s ease;
        }

        .layui-laypage a:hover {
            background-color: #3b82f6;
            color: white;
            transform: translateY(-1px);
        }

        .layui-laypage .layui-laypage-curr .layui-laypage-em {
            background-color: #3b82f6;
            border-radius: 6px;
        }

        /* 弹框样式 */
        .layui-layer {
            border-radius: 16px;
            overflow: hidden;
            box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
            z-index: 99999 !important;
        }

        .layui-layer-title {
            background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
            color: white;
            border-bottom: none;
            font-weight: 600;
            padding: 20px 24px;
        }

        .layui-layer-content {
            padding: 24px;
            background: #f8fafc;
        }

        /* 弹框内表单 */
        .layui-form-item {
            margin-bottom: 20px;
        }

        .layui-form-label {
            font-weight: 500;
            color: #374151;
            width: 100px;
        }

        .layui-input-block {
            margin-left: 100px;
        }

        .layui-input,
        .layui-select,
        .layui-textarea {
            border-radius: 8px;
            border: 2px solid #e5e7eb;
            padding: 12px 16px;
            font-size: 14px;
            transition: all 0.2s ease;
        }

        .layui-input:focus,
        .layui-select:focus,
        .layui-textarea:focus {
            border-color: #3b82f6;
            box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
        }

        /* 弹框内按钮 */
        .layui-btn {
            border-radius: 8px;
            font-weight: 500;
            padding: 10px 20px;
            font-size: 14px;
            transition: all 0.2s ease;
            border: none;
            text-align: center;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 6px;
            min-height: 40px;
            line-height: 1;
            white-space: nowrap;
        }

        /* 弹框内表格 */
        .layui-table {
            border-radius: 8px;
            overflow: hidden;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        }

        .layui-table thead tr {
            background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
        }

        .layui-table tbody tr:hover {
            background-color: #f8f9fa;
        }

        /* 弹框内标题 */
        .modal-section-title {
            font-size: 18px;
            font-weight: 600;
            color: #374151;
            margin: 20px 0 15px 0;
            padding-bottom: 10px;
            border-bottom: 2px solid #e5e7eb;
        }

        /* 弹框内按钮组 */
        .modal-button-group {
            display: flex;
            gap: 10px;
            margin: 15px 0;
            flex-wrap: wrap;
            align-items: center;
        }

        .modal-button-group .layui-btn {
            flex-shrink: 0;
            min-width: 100px;
        }

        /* 弹框底部按钮区域 */
        .modal-footer {
            background: #f8fafc;
            padding: 20px 24px;
            margin: 20px -24px -24px -24px;
            border-top: 1px solid #e5e7eb;
            text-align: right;
            display: flex;
            justify-content: flex-end;
            gap: 12px;
            align-items: center;
        }

        .modal-footer .layui-btn {
            min-width: 80px;
        }

        /* 弹框动画效果 */
        .layui-layer {
            animation: modalFadeIn 0.3s ease-out;
        }

        @@keyframes modalFadeIn {
            from {
                opacity: 0;
                transform: scale(0.9) translateY(-20px);
            }
            to {
                opacity: 1;
                transform: scale(1) translateY(0);
            }
        }

        /* 图标样式 */
        .layui-icon {
            font-size: 16px;
            line-height: 1;
        }

        /* 提示信息样式 */
        .modal-tip {
            color: #6b7280;
            font-size: 13px;
            margin: 5px 0 15px 0;
            padding: 12px;
            background: #f8fafc;
            border-radius: 8px;
            border-left: 3px solid #3b82f6;
        }

        /* 必填项标识 */
        .required-field::after {
            content: ' *';
            color: #ef4444;
            font-weight: bold;
        }

        /* 表格容器 */
        .table-container {
            background: white;
            border-radius: 8px;
            padding: 20px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
            margin: 15px 0;
        }

        /* 表单区域 */
        .form-section {
            background: white;
            border-radius: 8px;
            padding: 24px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
            margin-bottom: 20px;
        }

        /* 分隔线 */
        .section-divider {
            height: 1px;
            background: linear-gradient(90deg, transparent, #e5e7eb, transparent);
            margin: 20px 0;
        }

        /* 只读输入框 */
        .layui-input[readonly] {
            background-color: #f8fafc;
            color: #6b7280;
            cursor: not-allowed;
        }

        /* 复选框样式 */
        .layui-form-checkbox[lay-skin="primary"] i {
            border-radius: 4px;
            border-color: #d1d5db;
        }

        .layui-form-checked[lay-skin="primary"] i {
            background-color: #3b82f6;
            border-color: #3b82f6;
        }

        /* 动画定义 */
        @@keyframes shimmer {
            0% {
                transform: translateX(-100%) rotate(45deg);
            }
            100% {
                transform: translateX(100%) rotate(45deg);
            }
        }

        /* 响应式设计 */
        @@media (max-width: 768px) {
            .layui-fluid {
                padding: 16px;
            }

            .layui-card-body {
                padding: 20px;
            }

            .search-form {
                grid-template-columns: 1fr;
                gap: 16px;
            }

            .search-buttons {
                flex-direction: column;
                align-items: stretch;
            }

            .layui-btn {
                justify-content: center;
            }
        }

        /* 确保弹框层级正确 */
        .layui-layer-shade {
            z-index: 999998 !important;
        }

        .layui-layer {
            z-index: 999999 !important;
        }

        .layui-layer-content {
            z-index: 999999 !important;
            position: relative;
        }

        /* 强制选择用户弹框在最上层 */
        .layui-layer:has(#selectUserModal) {
            z-index: 9999999 !important;
            position: fixed !important;
        }

        /* 选择用户弹框内容强制层级 */
        .layui-layer:has(#selectUserModal) .layui-layer-content {
            z-index: 9999999 !important;
            position: relative !important;
        }

        /* 选择用户弹框本身强制层级 */
        #selectUserModal {
            z-index: 9999999 !important;
            position: relative !important;
        }

        /* 弹框美化样式 */
        .layui-layer {
            border-radius: 12px !important;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2) !important;
            border: none !important;
            overflow: hidden !important;
            z-index: 9999 !important;
        }

        .layui-layer-title {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
            color: white !important;
            font-weight: 600 !important;
            font-size: 16px !important;
            padding: 15px 20px !important;
            border-bottom: none !important;
            border-radius: 12px 12px 0 0 !important;
        }

        .layui-layer-content {
            padding: 20px !important;
            background: #f8f9fa !important;
            border-radius: 0 0 12px 12px !important;
        }

        /* 弹框内表单美化 */
        .layui-form-item {
            margin-bottom: 20px !important;
        }

        .layui-form-label {
            font-weight: 500 !important;
            color: #333 !important;
            width: 100px !important;
        }

        .layui-input-block {
            margin-left: 100px !important;
        }

        .layui-input,
        .layui-select,
        .layui-textarea {
            border-radius: 8px !important;
            border: 2px solid #e9ecef !important;
            padding: 10px 15px !important;
            font-size: 14px !important;
            transition: all 0.3s ease !important;
        }

        .layui-input:focus,
        .layui-select:focus,
        .layui-textarea:focus {
            border-color: #667eea !important;
            box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1) !important;
        }

        /* 弹框内按钮美化 */
        .layui-btn {
            border-radius: 8px !important;
            font-weight: 500 !important;
            padding: 8px 16px !important;
            font-size: 14px !important;
            transition: all 0.3s ease !important;
            border: none !important;
            text-align: center !important;
            display: inline-flex !important;
            align-items: center !important;
            justify-content: center !important;
            gap: 5px !important;
            min-height: 36px !important;
            line-height: 1 !important;
            white-space: nowrap !important;
        }

        /* 按钮内图标样式 */
        .layui-btn .layui-icon {
            font-size: 14px !important;
            line-height: 1 !important;
            margin: 0 !important;
        }

        /* 按钮内文字样式 */
        .layui-btn span,
        .layui-btn {
            line-height: 1 !important;
            vertical-align: middle !important;
        }

        .layui-btn-normal {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
        }

        .layui-btn-normal:hover {
            background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%) !important;
            transform: translateY(-2px) !important;
            box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3) !important;
        }

        .layui-btn-danger {
            background: linear-gradient(135deg, #ff6b6b 0%, #ee5a52 100%) !important;
        }

        .layui-btn-danger:hover {
            background: linear-gradient(135deg, #ff5252 0%, #d32f2f 100%) !important;
            transform: translateY(-2px) !important;
            box-shadow: 0 5px 15px rgba(255, 107, 107, 0.3) !important;
        }

        .layui-btn-primary {
            background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%) !important;
            color: #495057 !important;
            border: 2px solid #dee2e6 !important;
        }

        .layui-btn-primary:hover {
            background: linear-gradient(135deg, #e9ecef 0%, #dee2e6 100%) !important;
            transform: translateY(-2px) !important;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1) !important;
        }

        /* 弹框内表格美化 */
        .layui-table {
            border-radius: 8px !important;
            overflow: hidden !important;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
        }

        .layui-table thead tr {
            background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%) !important;
        }

        .layui-table tbody tr:hover {
            background-color: #f8f9fa !important;
        }

        /* 班组成员管理区域表格特殊美化 */
        .team-member-section .layui-table {
            border-radius: 10px !important;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1) !important;
            border: 1px solid #e9ecef !important;
            overflow: hidden !important;
        }

        .team-member-section .layui-table tbody {
            background: white !important;
        }

        .team-member-section .layui-table tbody td {
            padding: 10px 8px !important;
            border-bottom: 1px solid #f0f0f0 !important;
            vertical-align: middle !important;
        }

        .team-member-section .layui-table thead tr {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
            color: white !important;
            box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3) !important;
            position: relative !important;
        }

        .team-member-section .layui-table thead tr::after {
            content: '' !important;
            position: absolute !important;
            bottom: 0 !important;
            left: 0 !important;
            right: 0 !important;
            height: 2px !important;
            background: linear-gradient(90deg, #ffffff, #667eea, #ffffff) !important;
            opacity: 0.6 !important;
        }

        .team-member-section .layui-table thead th {
            color: white !important;
            font-weight: 600 !important;
            border-bottom: 2px solid rgba(255, 255, 255, 0.2) !important;
            padding: 12px 8px !important;
            text-align: center !important;
            font-size: 14px !important;
            text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3) !important;
            letter-spacing: 0.5px !important;
        }

        .team-member-section .layui-table tbody tr:hover {
            background: linear-gradient(135deg, #f8f9fa 0%, #e3f2fd 100%) !important;
            transform: translateY(-1px) !important;
            box-shadow: 0 2px 8px rgba(102, 126, 234, 0.1) !important;
        }

        /* 弹框内标题美化 */
        .modal-section-title {
            font-size: 18px !important;
            font-weight: 600 !important;
            color: #333 !important;
            margin: 20px 0 15px 0 !important;
            padding-bottom: 10px !important;
            border-bottom: 2px solid #e9ecef !important;
        }

        /* 班组成员管理标题特殊美化 */
        .team-member-section .modal-section-title {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
            color: white !important;
            padding: 12px 20px !important;
            margin: -20px -20px 20px -20px !important;
            border-radius: 12px 12px 0 0 !important;
            border-bottom: none !important;
            position: relative !important;
            box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2) !important;
        }

        .team-member-section .modal-section-title i {
            color: white !important;
            font-size: 20px !important;
        }

        /* 弹框内按钮组美化 */
        .modal-button-group {
            display: flex !important;
            gap: 10px !important;
            margin: 15px 0 !important;
            flex-wrap: wrap !important;
            align-items: center !important;
        }

        /* 弹框内按钮组中的按钮 */
        .modal-button-group .layui-btn {
            flex-shrink: 0 !important;
            min-width: 100px !important;
        }

        /* 班组成员管理区域按钮组特殊美化 */
        .team-member-section .modal-button-group {
            background: rgba(102, 126, 234, 0.05) !important;
            padding: 15px !important;
            border-radius: 8px !important;
            border: 1px solid rgba(102, 126, 234, 0.1) !important;
            margin: 15px 0 20px 0 !important;
        }

        /* 班组成员管理区域按钮特殊美化 */
        .team-member-section .layui-btn-normal {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
            border: none !important;
            box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3) !important;
        }

        .team-member-section .layui-btn-primary {
            background: linear-gradient(135deg, #28a745 0%, #20c997 100%) !important;
            color: white !important;
            border: none !important;
            box-shadow: 0 2px 8px rgba(40, 167, 69, 0.3) !important;
        }

        .team-member-section .layui-btn-danger {
            background: linear-gradient(135deg, #dc3545 0%, #fd7e14 100%) !important;
            border: none !important;
            box-shadow: 0 2px 8px rgba(220, 53, 69, 0.3) !important;
        }

        /* 弹框底部按钮区域美化 */
        .modal-footer {
            background: #f8f9fa !important;
            padding: 15px 20px !important;
            margin: 20px -20px -20px -20px !important;
            border-top: 1px solid #e9ecef !important;
            text-align: right !important;
            display: flex !important;
            justify-content: flex-end !important;
            gap: 10px !important;
            align-items: center !important;
        }

        /* 弹框底部按钮 */
        .modal-footer .layui-btn {
            min-width: 80px !important;
        }

        /* 弹框动画效果 */
        .layui-layer {
            animation: modalFadeIn 0.3s ease-out !important;
        }

        @@keyframes modalFadeIn {
            from {
                opacity: 0;
                transform: scale(0.9) translateY(-20px);
            }

            to {
                opacity: 1;
                transform: scale(1) translateY(0);
            }
        }

        /* 弹框内图标美化 */
        .layui-icon {
            margin-right: 5px !important;
        }

        /* 弹框内提示文字美化 */
        .modal-tip {
            color: #666 !important;
            font-size: 13px !important;
            margin: 5px 0 15px 0 !important;
            padding: 10px !important;
            background: #f8f9fa !important;
            border-radius: 6px !important;
            border-left: 3px solid #667eea !important;
        }

        /* 弹框内必填项标识 */
        .required-field::after {
            content: ' *' !important;
            color: #ff6b6b !important;
            font-weight: bold !important;
        }

        /* 弹框内表格容器美化 */
        .table-container {
            background: white !important;
            border-radius: 8px !important;
            padding: 15px !important;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05) !important;
            margin: 15px 0 !important;
        }

        /* 班组成员管理区域表格容器特殊美化 */
        .team-member-section .table-container {
            background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%) !important;
            border: 1px solid #e9ecef !important;
            border-radius: 10px !important;
            box-shadow: 0 3px 12px rgba(0, 0, 0, 0.08) !important;
            padding: 20px !important;
            position: relative !important;
        }

        .team-member-section .table-container::before {
            content: '👥 班组成员列表' !important;
            position: absolute !important;
            top: -10px !important;
            left: 20px !important;
            background: white !important;
            padding: 0 10px !important;
            font-size: 12px !important;
            color: #667eea !important;
            font-weight: 600 !important;
            z-index: 10 !important;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1) !important;
        }

        /* 弹框内表单组美化 */
        .form-section {
            background: white !important;
            border-radius: 8px !important;
            padding: 20px !important;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05) !important;
            margin-bottom: 20px !important;
        }

        /* 班组成员管理区域特殊美化 */
        .team-member-section {
            background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%) !important;
            border: 2px solid #e9ecef !important;
            border-radius: 12px !important;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08) !important;
            position: relative !important;
            overflow: hidden !important;
        }

        .team-member-section::before {
            content: '' !important;
            position: absolute !important;
            top: 0 !important;
            left: 0 !important;
            right: 0 !important;
            height: 3px !important;
            background: linear-gradient(90deg, #667eea, #764ba2, #667eea) !important;
        }

        /* 弹框内分隔线美化 */
        .section-divider {
            height: 1px !important;
            background: linear-gradient(90deg, transparent, #e9ecef, transparent) !important;
            margin: 20px 0 !important;
        }

        /* 弹框内只读输入框样式 */
        .layui-input[readonly] {
            background-color: #f8f9fa !important;
            color: #6c757d !important;
            cursor: not-allowed !important;
        }

        /* 弹框内表格高度优化 */
        .table-container .layui-table-view {
            max-height: 300px !important;
            overflow-y: auto !important;
            width: 100% !important;
        }

        /* 新建弹框内表格自适应 */
        #addTeamModal .table-container .layui-table-view {
            max-height: none !important;
            height: auto !important;
            overflow: visible !important;
            width: 100% !important;
        }

        #addTeamModal .table-container {
            height: auto !important;
            min-height: 200px !important;
            width: 100% !important;
            overflow-x: hidden !important;
        }

        #addTeamModal .layui-table {
            width: 100% !important;
            table-layout: auto !important;
        }

        /* 新建弹框内表格列宽自适应 */
        #addTeamModal .layui-table th:nth-child(1),
        #addTeamModal .layui-table td:nth-child(1) {
            width: 50px !important;
            min-width: 50px !important;
        }

        #addTeamModal .layui-table th:nth-child(2),
        #addTeamModal .layui-table td:nth-child(2) {
            width: 30% !important;
            min-width: 120px !important;
        }

        #addTeamModal .layui-table th:nth-child(3),
        #addTeamModal .layui-table td:nth-child(3) {
            width: 35% !important;
            min-width: 140px !important;
        }

        #addTeamModal .layui-table th:nth-child(4),
        #addTeamModal .layui-table td:nth-child(4) {
            width: 35% !important;
            min-width: 140px !important;
        }

        /* 编辑弹框内表格自适应 */
        #editTeamModal .table-container .layui-table-view {
            max-height: none !important;
            height: auto !important;
            overflow: visible !important;
            width: 100% !important;
        }

        /* 可编辑单元格样式 */
        .layui-table-cell[lay-event="LAYTABLE_TIPS"] {
            padding: 8px 12px !important;
            min-height: 36px !important;
            line-height: 20px !important;
            border: 1px solid #e6e6e6 !important;
            border-radius: 4px !important;
            background: #fff !important;
            transition: all 0.3s ease !important;
        }

        .layui-table-cell[lay-event="LAYTABLE_TIPS"]:hover {
            border-color: #5FB878 !important;
            box-shadow: 0 0 5px rgba(95, 184, 120, 0.3) !important;
        }

        .layui-table-cell[lay-event="LAYTABLE_TIPS"]:focus {
            border-color: #5FB878 !important;
            box-shadow: 0 0 8px rgba(95, 184, 120, 0.4) !important;
            outline: none !important;
        }

        /* 编辑状态下的输入框样式 */
        .layui-table-cell input[type="text"] {
            width: 100% !important;
            height: 100% !important;
            border: none !important;
            background: transparent !important;
            padding: 0 !important;
            margin: 0 !important;
            font-size: 14px !important;
            color: #333 !important;
            outline: none !important;
        }

        .layui-table-cell input[type="text"]:focus {
            background: #f8f8f8 !important;
        }

        /* 优化提示框样式 */
        .layui-layer-msg {
            border-radius: 8px !important;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
            border: none !important;
            font-size: 14px !important;
            font-weight: 500 !important;
            padding: 12px 20px !important;
            min-width: 200px !important;
            max-width: 400px !important;
            word-wrap: break-word !important;
            line-height: 1.5 !important;
            position: relative !important;
            overflow: visible !important;
        }

        /* 提示框图标样式 - 确保图标在前面 */
        .layui-layer-msg .layui-layer-ico {
            position: absolute !important;
            left: 20px !important;
            top: 50% !important;
            transform: translateY(-50%) !important;
            width: 20px !important;
            height: 20px !important;
            display: block !important;
            z-index: 2 !important;
        }

        /* 提示框文字样式 - 确保文字跟在图标后面 */
        .layui-layer-msg .layui-layer-content {
            margin-left: 60px !important;
            padding-left: 0 !important;
            white-space: normal !important;
            word-break: break-word !important;
            line-height: 1.5 !important;
            display: block !important;
        }

        /* 确保提示框内容不会重叠 */
        .layui-layer-msg * {
            box-sizing: border-box !important;
        }

        /* 成功提示框样式 */
        .layui-layer-msg.layui-layer-msg-1 {
            background: linear-gradient(135deg, #52c41a, #73d13d) !important;
            color: white !important;
        }

        /* 错误提示框样式 */
        .layui-layer-msg.layui-layer-msg-2 {
            background: linear-gradient(135deg, #ff4d4f, #ff7875) !important;
            color: white !important;
        }

        /* 警告提示框样式 */
        .layui-layer-msg.layui-layer-msg-0 {
            background: linear-gradient(135deg, #faad14, #ffc53d) !important;
            color: white !important;
        }

        /* 提示框动画效果 */
        .layui-layer-msg {
            animation: msgSlideIn 0.3s ease-out !important;
        }

        @@keyframes msgSlideIn {
            from {
                opacity: 0;
                transform: translateY(-20px) scale(0.9);
            }

            to {
                opacity: 1;
                transform: translateY(0) scale(1);
            }

        }

        /* 提示框关闭动画 */
        .layui-layer-msg.layui-layer-msg-out {
            animation: msgSlideOut 0.3s ease-in !important;
        }

        @@keyframes msgSlideOut {
            from {
                opacity: 1;
                transform: translateY(0) scale(1);
            }

            to {
                opacity: 0;
                transform: translateY(-20px) scale(0.9);
            }
        }

        /* 导入弹窗样式 */
        .import-modal {
            padding: 20px;
        }

        .import-modal .modal-header {
            margin-bottom: 20px;
            padding-bottom: 15px;
            border-bottom: 2px solid #e9ecef;
        }

        .import-modal .modal-header h3 {
            margin: 0;
            font-size: 18px;
            font-weight: 600;
            color: #333;
            display: flex;
            align-items: center;
        }

        .import-modal .modal-header h3 i {
            margin-right: 8px;
            color: #667eea;
        }

        .import-modal .modal-body {
            margin-bottom: 20px;
        }

        .upload-area {
            border: 2px dashed #ddd;
            border-radius: 8px;
            padding: 30px;
            text-align: center;
            background: #fafafa;
            transition: all 0.3s ease;
        }

        .upload-area:hover {
            border-color: #667eea;
            background: #f8f9ff;
        }

        .upload-buttons {
            margin-bottom: 20px;
            display: flex;
            gap: 10px;
            justify-content: center;
            flex-wrap: wrap;
        }

        .upload-info {
            margin-bottom: 20px;
        }

        .info-box {
            display: flex;
            align-items: flex-start;
            background: #fff3cd;
            border: 1px solid #ffeaa7;
            border-radius: 6px;
            padding: 15px;
            margin: 0 auto;
            max-width: 400px;
        }

        .info-box i {
            color: #f39c12;
            font-size: 20px;
            margin-right: 10px;
            margin-top: 2px;
        }

        .info-content {
            flex: 1;
        }

        .info-title {
            font-weight: 600;
            color: #856404;
            margin-bottom: 5px;
        }

        .info-text {
            color: #856404;
            font-size: 14px;
            line-height: 1.4;
        }

        .file-list {
            margin-top: 20px;
        }

        .file-item {
            display: flex;
            align-items: center;
            justify-content: space-between;
            background: white;
            border: 1px solid #e9ecef;
            border-radius: 6px;
            padding: 12px;
            margin-bottom: 10px;
        }

        .file-item .file-info {
            display: flex;
            align-items: center;
            flex: 1;
        }

        .file-item .file-icon {
            color: #28a745;
            font-size: 18px;
            margin-right: 10px;
        }

        .file-item .file-name {
            font-weight: 500;
            color: #333;
        }

        .file-item .file-size {
            color: #666;
            font-size: 12px;
            margin-left: 10px;
        }

        .file-item .file-remove {
            color: #dc3545;
            cursor: pointer;
            padding: 5px;
            border-radius: 3px;
            transition: background-color 0.2s;
        }

        .file-item .file-remove:hover {
            background-color: #f8d7da;
        }

        .upload-progress {
            margin-top: 15px;
            display: none;
        }

        .progress-bar {
            width: 100%;
            height: 8px;
            background-color: #e9ecef;
            border-radius: 4px;
            overflow: hidden;
        }

        .progress-fill {
            height: 100%;
            background: linear-gradient(90deg, #667eea, #764ba2);
            width: 0%;
            transition: width 0.3s ease;
        }

        .progress-text {
            text-align: center;
            margin-top: 8px;
            font-size: 12px;
            color: #666;
        }

        /* 列设置弹窗样式 */
        .column-settings-modal {
            padding: 20px;
        }

        .column-settings-modal .modal-header {
            margin-bottom: 20px;
            padding-bottom: 15px;
            border-bottom: 2px solid #e9ecef;
        }

        .column-settings-modal .modal-header h3 {
            margin: 0 0 5px 0;
            font-size: 18px;
            font-weight: 600;
            color: #333;
        }

        .column-settings-modal .modal-header p {
            margin: 0;
            color: #666;
            font-size: 14px;
        }

        .column-settings-modal .modal-body {
            margin-bottom: 20px;
        }

        .column-settings-modal .layui-table {
            margin: 0;
        }

        .column-settings-modal .layui-table th {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            font-weight: 600;
        }

        .column-settings-modal .layui-table td {
            vertical-align: middle;
        }

        .column-settings-modal .drag-handle {
            display: flex;
            align-items: center;
            padding: 8px 0;
        }

        .column-settings-modal .draggable-row {
            transition: all 0.3s ease;
        }

        .column-settings-modal .draggable-row:hover {
            background-color: #f8f9fa;
            transform: translateX(5px);
        }

        .column-settings-modal .draggable-row.ui-sortable-helper {
            background: white;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
            border-radius: 4px;
        }

        .column-settings-modal .draggable-row.dragging {
            background: #f0f8ff !important;
            border: 2px dashed #667eea !important;
            opacity: 0.8;
        }

        .column-settings-modal .ui-state-highlight {
            background: #e3f2fd !important;
            border: 2px dashed #2196f3 !important;
            height: 50px;
            margin: 5px 0;
        }

        .column-settings-modal .drag-handle {
            display: flex;
            align-items: center;
            padding: 8px 0;
            transition: all 0.3s ease;
        }

        .column-settings-modal .drag-handle:hover {
            background: rgba(102, 126, 234, 0.1);
            border-radius: 4px;
            padding: 8px 4px;
        }

        .column-settings-modal .drag-handle i {
            transition: all 0.3s ease;
        }

        .column-settings-modal .drag-handle:hover i {
            color: #667eea !important;
            transform: scale(1.2);
        }

        .column-settings-modal .modal-footer {
            display: flex;
            justify-content: flex-end;
            gap: 10px;
            padding-top: 15px;
            border-top: 1px solid #e9ecef;
        }

        #editTeamModal .table-container {
            height: auto !important;
            min-height: 200px !important;
            width: 100% !important;
            overflow-x: hidden !important;
        }

        /* 编辑弹框内表格自适应 */
        #editTeamModal .layui-table {
            width: 100% !important;
            table-layout: auto !important;
        }

        /* 编辑弹框内表格行自适应 */
        #editTeamModal .layui-table tbody tr {
            height: auto !important;
            min-height: 40px !important;
        }

        /* 编辑弹框内表格单元格自适应 */
        #editTeamModal .layui-table td,
        #editTeamModal .layui-table th {
            padding: 8px 12px !important;
            vertical-align: middle !important;
            white-space: nowrap !important;
            overflow: hidden !important;
            text-overflow: ellipsis !important;
        }

        /* 编辑弹框内表格列宽自适应 */
        #editTeamModal .layui-table th:nth-child(1),
        #editTeamModal .layui-table td:nth-child(1) {
            width: 50px !important;
            min-width: 50px !important;
        }

        #editTeamModal .layui-table th:nth-child(2),
        #editTeamModal .layui-table td:nth-child(2) {
            width: 30% !important;
            min-width: 120px !important;
        }

        #editTeamModal .layui-table th:nth-child(3),
        #editTeamModal .layui-table td:nth-child(3) {
            width: 35% !important;
            min-width: 140px !important;
        }

        #editTeamModal .layui-table th:nth-child(4),
        #editTeamModal .layui-table td:nth-child(4) {
            width: 35% !important;
            min-width: 140px !important;
        }

        /* 弹框内滚动条美化 */
        .table-container .layui-table-view::-webkit-scrollbar {
            width: 6px !important;
        }

        .table-container .layui-table-view::-webkit-scrollbar-track {
            background: #f1f1f1 !important;
            border-radius: 3px !important;
        }

        .table-container .layui-table-view::-webkit-scrollbar-thumb {
            background: #c1c1c1 !important;
            border-radius: 3px !important;
        }

        .table-container .layui-table-view::-webkit-scrollbar-thumb:hover {
            background: #a8a8a8 !important;
        }

        /* 弹框内加载状态美化 */
        .layui-btn-disabled {
            opacity: 0.6 !important;
            cursor: not-allowed !important;
        }

        /* 弹框内图标动画效果 */
        .layui-btn .layui-icon {
            transition: transform 0.3s ease !important;
        }

        .layui-btn:hover .layui-icon {
            transform: scale(1.1) !important;
        }

        /* 班组成员管理区域特殊动画效果 */
        .team-member-section {
            animation: sectionFadeIn 0.5s ease-out !important;
        }

        @@keyframes sectionFadeIn {
            from {
                opacity: 0;
                transform: translateY(20px);
            }

            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        /* 班组成员管理区域按钮悬停效果增强 */
        .team-member-section .layui-btn:hover {
            transform: translateY(-3px) !important;
            box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15) !important;
        }

        /* 班组成员管理区域表格行悬停效果增强 */
        .team-member-section .layui-table tbody tr {
            transition: all 0.3s ease !important;
        }

        .team-member-section .layui-table tbody tr:hover {
            background: linear-gradient(135deg, #f8f9fa 0%, #e3f2fd 100%) !important;
            transform: translateY(-2px) !important;
            box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15) !important;
        }

        /* 弹框内表格行悬停效果增强 */
        .table-container .layui-table tbody tr:hover {
            background-color: #f8f9fa !important;
            transform: translateY(-1px) !important;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
            transition: all 0.3s ease !important;
        }

        /* 弹框内复选框美化 */
        .table-container .layui-form-checkbox[lay-skin="primary"] i {
            border-radius: 3px !important;
            border-color: #ddd !important;
        }

        .table-container .layui-form-checked[lay-skin="primary"] i {
            background-color: #667eea !important;
            border-color: #667eea !important;
        }

        /* 移除任何可能的遮罩效果 */
        .layui-layer-shade,
        .layui-layer-shade[layui-layer-shade] {
            background: none !important;
            opacity: 0 !important;
            display: none !important;
        }

        /* 确保按钮可以正常点击 */
        .layui-btn {
            pointer-events: auto !important;
            cursor: pointer !important;
            z-index: 10000 !important;
        }

        /* 确保表单元素可以正常交互 */
        .layui-form-item input,
        .layui-form-item select,
        .layui-form-item button {
            pointer-events: auto !important;
            z-index: 10000 !important;
        }

        /* 页面整体样式优化 */
        .layui-fluid {
            padding: 20px;
            background-color: #f5f5f5;
        }

        /* 卡片样式优化 */
        .layui-card {
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
            border: none;
            margin-bottom: 20px;
        }

        .layui-card-body {
            background-color: white;
        }

        /* 表格样式优化 */
        .layui-table {
            border-radius: 6px;
            overflow: hidden;
        }

        .layui-table thead tr {
            background-color: #fafafa;
        }

        .layui-table tbody tr:hover {
            background-color: #f8f9fa;
        }

        /* 按钮样式优化 */
        .layui-btn {
            border-radius: 6px;
            font-weight: 500;
            transition: all 0.3s ease;
        }

        .layui-btn:hover {
            transform: translateY(-1px);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        }

        /* 输入框样式优化 */
        .layui-input {
            border-radius: 6px;
            border: 1px solid #e6e6e6;
            transition: border-color 0.3s ease;
        }

        .layui-input:focus {
            border-color: #1E9FFF;
            box-shadow: 0 0 0 2px rgba(30, 159, 255, 0.2);
        }

        /* 班组类型标签样式 */
        .team-type-tag {
            display: inline-block;
            padding: 2px 8px;
            border-radius: 12px;
            font-size: 12px;
            font-weight: 500;
            color: white;
        }

        .team-type-warehouse {
            background-color: #1E9FFF;
        }

        .team-type-assembly {
            background-color: #FFB800;
        }

        .team-type-machining {
            background-color: #FF5722;
        }

        .team-type-injection {
            background-color: #5FB878;
        }

        /* 搜索区域样式 */
        .search-area {
            background-color: white;
            padding: 15px;
            border-radius: 8px;
            margin-bottom: 15px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        }

        .search-form {
            display: flex;
            flex-wrap: wrap;
            gap: 15px;
            align-items: flex-end;
        }

        .search-form .layui-form-item {
            margin-bottom: 0;
            flex: 1;
            min-width: 200px;
        }

        .search-buttons {
            display: flex;
            gap: 10px;
            flex-wrap: wrap;
        }

        /* 表格容器样式 */
        .table-container {
            background-color: white;
            border-radius: 8px;
            overflow: hidden;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        }

        /* 分页样式 */
        .layui-laypage {
            text-align: center;
            padding: 15px 0;
        }

        /* 响应式设计 */
        @@media (max-width: 768px) {
            .search-form {
                flex-direction: column;
            }

            .search-form .layui-form-item {
                min-width: 100%;
            }

            .search-buttons {
                justify-content: center;
            }
        }
    </style>
}

<div class="layui-fluid">
    <!-- 班组管理 -->
    <div class="layui-card">
        <div class="layui-card-header">
            <h3>班组</h3>
        </div>
        <div class="layui-card-body">
            <!-- 搜索区域 -->
            <div class="search-area">
                <form class="layui-form search-form">
                    <div class="layui-form-item">
                        <label class="layui-form-label">班组名称:</label>
                        <div class="layui-input-block">
                            <input type="text" id="teamName" placeholder="班组名称" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">编组编码:</label>
                        <div class="layui-input-block">
                            <input type="text" id="teamCode" placeholder="编组编码" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">班组类型:</label>
                        <div class="layui-input-block">
                            <select id="teamType" class="layui-select">
                                <option value="">全部</option>
                                <option value="0">仓库</option>
                                <option value="1">组装</option>
                                <option value="2">机加工</option>
                                <option value="3">注塑</option>
                            </select>
                        </div>
                    </div>
                    <div class="search-buttons">
                        <button type="button" class="layui-btn layui-btn-normal" onclick="searchTeams()">
                            <i class="layui-icon layui-icon-search"></i> 查询
                        </button>
                        <button type="button" class="layui-btn layui-btn-primary" onclick="showAdvancedSearch()">
                            <i class="layui-icon layui-icon-search"></i> 高级查询
                        </button>
                        <button type="button" class="layui-btn layui-btn-normal" onclick="addTeam()">
                            <i class="layui-icon layui-icon-add-1"></i> 新建
                        </button>
                        <button type="button" class="layui-btn layui-btn-warm" onclick="editTeam()">
                            <i class="layui-icon layui-icon-edit"></i> 编辑
                        </button>
                        <button type="button" class="layui-btn layui-btn-danger" onclick="deleteTeam()">
                            <i class="layui-icon layui-icon-delete"></i> 删除
                        </button>
                        <button type="button" class="layui-btn layui-btn-normal" onclick="importTeam()">
                            <i class="layui-icon layui-icon-upload"></i> 导入
                        </button>
                        <button type="button" class="layui-btn layui-btn-normal" onclick="exportTeam()">
                            <i class="layui-icon layui-icon-download-circle"></i> 导出
                        </button>
                        <button type="button" class="layui-btn layui-btn-normal" onclick="showColumnSettings()">
                            <i class="layui-icon layui-icon-set"></i> 显示列设置
                        </button>
                    </div>
                </form>
            </div>

            <!-- 表格区域 -->
            <div class="table-container">
                <table id="teamTable" lay-filter="teamTable"></table>
            </div>
        </div>
    </div>

    <!-- 班组成员管理 -->
    <div class="layui-card">
        <div class="layui-card-header">
            <h3>班组-成员</h3>
        </div>
        <div class="layui-card-body">
            <!-- 表格区域 -->
            <div class="table-container">
                <table id="teamMemberTable" lay-filter="teamMemberTable"></table>
            </div>
        </div>
    </div>
</div>

<!-- 导入弹窗 -->
<div id="importModal" style="display: none;">
    <div class="import-modal">
        <div class="modal-header">
            <h3><i class="layui-icon layui-icon-upload"></i> 班组-导入</h3>
        </div>
        <div class="modal-body">
            <div class="upload-area">
                <div class="upload-buttons">
                    <button type="button" class="layui-btn layui-btn-default" onclick="selectFile()">
                        <i class="layui-icon layui-icon-file"></i> 选择文件
                    </button>
                    <button type="button" class="layui-btn layui-btn-normal" onclick="downloadTemplate()">
                        <i class="layui-icon layui-icon-download"></i> ↓下载模板
                    </button>
                    <button type="button" class="layui-btn layui-btn-warm" onclick="uploadFile()">
                        <i class="layui-icon layui-icon-upload"></i> ↑上传文件
                    </button>
                </div>
                <div class="upload-info">
                    <div class="info-box">
                        <i class="layui-icon layui-icon-about"></i>
                        <div class="info-content">
                            <div class="info-title">上传说明</div>
                            <div class="info-text">只能上传excel文件,文件大小不超过100M</div>
                        </div>
                    </div>
                </div>
                <div class="file-list" id="fileList">
                    <!-- 文件列表将在这里显示 -->
                </div>
                <div class="upload-progress">
                    <div class="progress-bar">
                        <div class="progress-fill"></div>
                    </div>
                    <div class="progress-text">上传进度: 0%</div>
                </div>
            </div>
        </div>
        <div class="modal-footer">
            <button type="button" class="layui-btn layui-btn-default" onclick="closeImportModal()">
                <i class="layui-icon layui-icon-close"></i> 取消
            </button>
        </div>
    </div>
</div>

<!-- 列设置弹窗 -->
<div id="columnSettingsModal" style="display: none;">
    <div class="column-settings-modal">
        <div class="modal-header">
            <h3>显示列设置</h3>
            <p>选择要显示的表格列，拖动可调整顺序</p>
        </div>
        <div class="modal-body">
            <table class="layui-table" id="columnSettingsTable">
                <thead>
                    <tr>
                        <th width="60">#</th>
                        <th>列名</th>
                        <th width="100">是否显示</th>
                    </tr>
                </thead>
                <tbody id="columnSettingsBody">
                    <tr data-field="teamName" class="draggable-row">
                        <td>1</td>
                        <td class="drag-handle" style="cursor: move;">
                            <i class="layui-icon layui-icon-drag" style="margin-right: 8px; color: #999;"></i>
                            班组名称
                        </td>
                        <td><input type="checkbox" name="teamName" lay-skin="primary" title="显示" checked></td>
                    </tr>
                    <tr data-field="teamCode" class="draggable-row">
                        <td>2</td>
                        <td class="drag-handle" style="cursor: move;">
                            <i class="layui-icon layui-icon-drag" style="margin-right: 8px; color: #999;"></i>
                            编组编码
                        </td>
                        <td><input type="checkbox" name="teamCode" lay-skin="primary" title="显示" checked></td>
                    </tr>
                    <tr data-field="teamType" class="draggable-row">
                        <td>3</td>
                        <td class="drag-handle" style="cursor: move;">
                            <i class="layui-icon layui-icon-drag" style="margin-right: 8px; color: #999;"></i>
                            班组类型
                        </td>
                        <td><input type="checkbox" name="teamType" lay-skin="primary" title="显示" checked></td>
                    </tr>
                    <tr data-field="remark" class="draggable-row">
                        <td>4</td>
                        <td class="drag-handle" style="cursor: move;">
                            <i class="layui-icon layui-icon-drag" style="margin-right: 8px; color: #999;"></i>
                            备注
                        </td>
                        <td><input type="checkbox" name="remark" lay-skin="primary" title="显示" checked></td>
                    </tr>
                    <tr data-field="creator" class="draggable-row">
                        <td>5</td>
                        <td class="drag-handle" style="cursor: move;">
                            <i class="layui-icon layui-icon-drag" style="margin-right: 8px; color: #999;"></i>
                            创建人
                        </td>
                        <td><input type="checkbox" name="creator" lay-skin="primary" title="显示" checked></td>
                    </tr>
                    <tr data-field="createTime" class="draggable-row">
                        <td>6</td>
                        <td class="drag-handle" style="cursor: move;">
                            <i class="layui-icon layui-icon-drag" style="margin-right: 8px; color: #999;"></i>
                            创建时间
                        </td>
                        <td><input type="checkbox" name="createTime" lay-skin="primary" title="显示" checked></td>
                    </tr>
                    <tr data-field="modifier" class="draggable-row">
                        <td>7</td>
                        <td class="drag-handle" style="cursor: move;">
                            <i class="layui-icon layui-icon-drag" style="margin-right: 8px; color: #999;"></i>
                            修改人
                        </td>
                        <td><input type="checkbox" name="modifier" lay-skin="primary" title="显示" checked></td>
                    </tr>
                    <tr data-field="modifyTime" class="draggable-row">
                        <td>8</td>
                        <td class="drag-handle" style="cursor: move;">
                            <i class="layui-icon layui-icon-drag" style="margin-right: 8px; color: #999;"></i>
                            修改时间
                        </td>
                        <td><input type="checkbox" name="modifyTime" lay-skin="primary" title="显示" checked></td>
                    </tr>
                </tbody>
            </table>
        </div>
        <div class="modal-footer">
            <button type="button" class="layui-btn layui-btn-primary" id="resetColumnSettings">
                <i class="layui-icon layui-icon-refresh"></i> 重置
            </button>
            <button type="button" class="layui-btn layui-btn-default" id="cancelColumnSettings">
                <i class="layui-icon layui-icon-close"></i> 取消
            </button>
            <button type="button" class="layui-btn layui-btn-normal" id="confirmColumnSettings">
                <i class="layui-icon layui-icon-ok"></i> 确定
            </button>
        </div>
    </div>
</div>

<!-- 高级查询弹窗 -->
<div id="advancedSearchModal" style="display: none;">
    <div class="form-section">
        <div class="modal-section-title">
            <i class="layui-icon layui-icon-search" style="margin-right: 8px; color: #667eea;"></i>
            高级查询条件
        </div>
    <form class="layui-form" lay-filter="advancedSearchForm">
        <div class="layui-form-item">
            <label class="layui-form-label">班组名称:</label>
            <div class="layui-input-block">
                    <input type="text" name="advancedTeamName" placeholder="请输入班组名称" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">编组编码:</label>
            <div class="layui-input-block">
                    <input type="text" name="advancedTeamCode" placeholder="请输入编组编码" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">班组类型:</label>
            <div class="layui-input-block">
                <select name="advancedTeamType" class="layui-select">
                        <option value="">全部类型</option>
                    <option value="0">仓库</option>
                    <option value="1">组装</option>
                    <option value="2">机加工</option>
                    <option value="3">注塑</option>
                </select>
            </div>
        </div>
            <div class="modal-tip">
                <i class="layui-icon layui-icon-tips"></i>
                高级查询支持多条件组合查询，可以更精确地筛选班组信息
            </div>
        </form>
    </div>

    <div class="modal-footer">
                <button type="button" class="layui-btn layui-btn-normal" onclick="advancedSearch()">
            <i class="layui-icon layui-icon-search"></i> 查询
                </button>
                <button type="button" class="layui-btn layui-btn-primary" onclick="resetAdvancedSearch()">
            <i class="layui-icon layui-icon-refresh"></i> 重置
                </button>
                <button type="button" class="layui-btn layui-btn-default" onclick="closeAdvancedSearch()">
                    <i class="layui-icon layui-icon-close"></i> 关闭
                </button>
            </div>
</div>

<script type="text/html" id="teamTypeTpl">
        {{# if(d.teamType === 0) { }}
            <span class="team-type-tag team-type-warehouse">仓库</span>
        {{# } else if(d.teamType === 1) { }}
            <span class="team-type-tag team-type-assembly">组装</span>
        {{# } else if(d.teamType === 2) { }}
            <span class="team-type-tag team-type-machining">机加工</span>
        {{# } else if(d.teamType === 3) { }}
            <span class="team-type-tag team-type-injection">注塑</span>
        {{# } else { }}
            <span class="team-type-tag">未知</span>
        {{# } }}
    </script>

<script type="text/html" id="dateTimeTpl">
        {{# if(d && d !== '' && d !== null && d !== undefined) { }}
            {{# var date = new Date(d); }}
            {{# if(date.getTime() && !isNaN(date.getTime())) { }}
                {{# var year = date.getFullYear(); }}
                {{# var month = (date.getMonth() + 1).toString().padStart(2, '0'); }}
                {{# var day = date.getDate().toString().padStart(2, '0'); }}
                {{# var hours = date.getHours().toString().padStart(2, '0'); }}
                {{# var minutes = date.getMinutes().toString().padStart(2, '0'); }}
                {{# var seconds = date.getSeconds().toString().padStart(2, '0'); }}
                {{ year }}-{{ month }}-{{ day }} {{ hours }}:{{ minutes }}:{{ seconds }}
            {{# } else { }}
                -
            {{# } }}
        {{# } else { }}
            -
        {{# } }}
    </script>



@section Scripts {
    <!-- 引入jQuery UI库支持拖拽功能 -->
    <script src="https://code.jquery.com/ui/1.13.2/jquery-ui.min.js"></script>
    <link rel="stylesheet" href="https://code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css">

    <script>
        let teamTable;
        let teamMemberTable;
        let selectedTeamId = null;

        // 列设置相关变量
        var columnSettings = {
            teamName: { visible: true, order: 1 },
            teamCode: { visible: true, order: 2 },
            teamType: { visible: true, order: 3 },
            remark: { visible: true, order: 4 },
            creator: { visible: true, order: 5 },
            createTime: { visible: true, order: 6 },
            modifier: { visible: true, order: 7 },
            modifyTime: { visible: true, order: 8 }
        };

        // 列配置定义
        var columnConfigs = {
            teamName: { field: 'teamName', title: '班组名称', minWidth: 150, sort: true, templet: function(d){ return '<a href="javascript:;" lay-event="editByName" style="color:#1E9FFF;">' + (d.teamName || '') + '</a>'; } },
            teamCode: { field: 'teamCode', title: '编组编码', minWidth: 150, sort: true },
            teamType: { field: 'teamType', title: '班组类型', minWidth: 120, templet: '#teamTypeTpl' },
            remark: { field: 'remark', title: '备注', minWidth: 200 },
            creator: { field: 'creator', title: '创建人', minWidth: 120 },
            createTime: { field: 'createTime', title: '创建时间', minWidth: 180, sort: true },
            modifier: { field: 'modifier', title: '修改人', minWidth: 120 },
            modifyTime: { field: 'modifyTime', title: '修改时间', minWidth: 180, sort: true }
        };

        // 全局提示框管理
        let currentMsgIndex = null;

        // 统一的提示框显示函数
        function showMessage(message, icon = 1, time = 2000) {
            // 如果当前有提示框，先关闭
            if (currentMsgIndex !== null) {
                layui.layer.close(currentMsgIndex);
                currentMsgIndex = null;
            }

            // 显示新的提示框
            currentMsgIndex = layui.layer.msg(message, {
                icon: icon,
                time: time,
                shade: [0.3, '#000'],
                shadeClose: true,
                anim: 1,
                isOutAnim: true
            });

            // 设置定时器清除索引
            setTimeout(function () {
                currentMsgIndex = null;
            }, time);
        }

        // 错误提示框
        function showError(message, time = 3000) {
            showMessage(message, 2, time);
        }

        // 成功提示框
        function showSuccess(message, time = 2000) {
            showMessage(message, 1, time);
        }

        // 警告提示框
        function showWarning(message, time = 3000) {
            showMessage(message, 0, time);
        }

        layui.use(['table', 'layer', 'form'], function () {
            var table = layui.table;
            var layer = layui.layer;
            var form = layui.form;

            // 初始化班组表格
            teamTable = table.render({
                elem: '#teamTable',
                url: '/Team/GetTeamPage',
                method: 'get',
                page: true,
                limit: 30,
                limits: [10, 20, 30, 50, 100],
                parseData: function (res) {

                    var processedData = processTableData(res.pageData || []);
                    return {
                        "code": res.code === 200 ? 0 : 1, // 后端返回200表示成功，前端期望0
                        "msg": res.msg || "",
                        "count": res.totaCount || 0,
                        "data": processedData
                    };
                },
                cols: [getTableColumns()],
                done: function (res) {
                    // 表格渲染完成后的回调
                }
            });

            // 初始化班组成员表格 - 初始化为空数据，只用于显示
            teamMemberTable = table.render({
                elem: '#teamMemberTable',
                data: [], // 初始化为空数据
                page: false, // 去掉分页
                cols: [[
                    { field: 'memberName', title: '成员名称', minWidth: 150, sort: true },
                    { field: 'memberRealName', title: '成员姓名', minWidth: 150, sort: true },
                    { field: 'phone', title: '电话号码', minWidth: 150 },
                    { field: 'creator', title: '创建人', minWidth: 120 },
                    { field: 'createTime', title: '创建时间', minWidth: 180, sort: true },
                    { field: 'modifier', title: '修改人', minWidth: 120 },
                    { field: 'modifyTime', title: '修改时间', minWidth: 180, sort: true }
                ]],
                done: function (res) {
                    // 表格渲染完成后的回调
                }
            });

            // 监听班组表格行点击
            table.on('row(teamTable)', function (obj) {

                selectedTeamId = obj.data.id;


                // 直接调用API获取数据，然后重新渲染表格
                $.ajax({
                    url: '/Team/GetTeamMemberPage',
                    method: 'GET',
                    data: { teamId: selectedTeamId },
                    success: function (res) {
    
                        if (res.code === 200 && res.pageData) {
                            // 处理时间格式化
                            var processedData = processTableData(res.pageData);
                            // 重新渲染班组成员表格
                            teamMemberTable.reload({
                                data: processedData
                            });
                        } else {
                            // 如果没有数据，清空表格
                            teamMemberTable.reload({
                                data: []
                            });
                        }
                    },
                    error: function (xhr, status, error) {
    
                        // 出错时清空表格
                        teamMemberTable.reload({
                            data: []
                        });
                    }
                });
            });

            table.on('tool(teamTable)', function(obj){
                if(obj.event === 'editByName'){
                    showEditTeamModal(obj.data);
                }
            });

        });

        // 搜索班组
        function searchTeams() {
            var teamName = $('#teamName').val();
            var teamCode = $('#teamCode').val();
            var teamType = $('#teamType').val();

            teamTable.reload({
                url: '/Team/GetTeamPage',
                where: {
                    teamName: teamName,
                    teamCode: teamCode,
                    teamType: teamType
                },
                page: { curr: 1 }
            });
        }

        // 显示高级查询
        function showAdvancedSearch() {
            layui.layer.open({
                type: 1,
                title: '高级查询',
                area: ['700px', '500px'],
                content: $('#advancedSearchModal'),
                zIndex: 99999, // 设置最高层级
                success: function (layero, index) {
                    // 弹窗打开成功后的回调
                    // 确保层级正确
                    setTimeout(function () {
                        ensureModalZIndex();
                    }, 100);
                }
            });
        }

        // 高级查询
        function advancedSearch() {
            var formData = layui.form.val('advancedSearchForm');

            teamTable.reload({
                url: '/Team/GetTeamPage',
                where: {
                    teamName: formData.advancedTeamName,
                    teamCode: formData.advancedTeamCode,
                    teamType: formData.advancedTeamType
                },
                page: { curr: 1 }
            });

            layui.layer.closeAll();
        }

        // 重置高级查询
        function resetAdvancedSearch() {
            layui.form.val('advancedSearchForm', {
                advancedTeamName: '',
                advancedTeamCode: '',
                advancedTeamType: ''
            });
        }

        // 关闭高级查询
        function closeAdvancedSearch() {
            layui.layer.closeAll();
        }

        // 新建班组
        function addTeam() {
            showAddTeamModal();
        }

        // 显示添加班组弹窗
        function showAddTeamModal() {
            window.addTeamModalIndex = layui.layer.open({
                type: 1,
                title: '班组(新建)',
                area: ['1000px', '750px'],
                content: $('#addTeamModal'),
                zIndex: 99999, // 设置最高层级
                success: function (layero, index) {
                    // 初始化表单
                    layui.form.render();
                    // 初始化班组成员表格
                    initTeamMemberTable();
                    // 确保层级正确
                    setTimeout(function () {
                        ensureModalZIndex();
                    }, 100);
                }
            });
        }

        // 显示编辑班组弹窗
        function showEditTeamModal(teamData) {
            // 先获取班组详情
            $.ajax({
                url: '/Team/GetTeamDetail',
                method: 'GET',
                data: { teamId: teamData.id },
                success: function (res) {
    
                    if (res.code === 200 && res.data) {
                        var teamDetail = res.data;

                        // 填充表单数据
                        layui.form.val('editTeamForm', {
                            teamId: teamDetail.id,
                            teamName: teamDetail.teamName,
                            teamCode: teamDetail.teamCode,
                            teamType: teamDetail.teamType.toString(),
                            remark: teamDetail.remark || ''
                        });

                        // 初始化班组成员表格
                        initEditTeamMemberTable(teamDetail.teamMembers || []);

                        // 打开编辑弹窗
                        window.editTeamModalIndex = layui.layer.open({
                            type: 1,
                            title: '班组(编辑)',
                            area: ['1000px', '750px'],
                            content: $('#editTeamModal'),
                            zIndex: 99999, // 设置最高层级
                            success: function (layero, index) {
                                layui.form.render();
                                // 确保层级正确
                                setTimeout(function () {
                                    ensureModalZIndex();
                                }, 100);
                            }
                        });
                    } else {
                        showError(res.msg || '获取班组详情失败');
                    }
                },
                error: function () {
                    showError('获取班组详情失败');
                }
            });
        }

        // 初始化弹窗内的班组成员表格
        function initTeamMemberTable() {
            layui.table.render({
                elem: '#modalTeamMemberTable', // 使用不同的ID
                data: [],
                page: false,
                edit: 'cell', // 启用单元格编辑
                id: 'modalTeamMemberTable', // 添加唯一标识符
                cols: [[
                    { type: 'checkbox', fixed: 'left' },
                    { field: 'memberName', title: '成员名称', minWidth: 150, edit: 'text' },
                    { field: 'memberRealName', title: '成员姓名', minWidth: 150, edit: 'text' },
                    { field: 'phone', title: '电话号码', minWidth: 150, edit: 'text' }
                ]],
                done: function() {
                    // 监听单元格编辑事件
                    layui.table.on('edit(modalTeamMemberTable)', function(obj) {
                        console.log('新建弹窗编辑单元格:', obj.field, '新值:', obj.value, '行数据:', obj.data);
                        // 更新缓存中的数据
                        var currentData = layui.table.cache.modalTeamMemberTable || [];
                        if (currentData[obj.data.LAY_TABLE_INDEX]) {
                            currentData[obj.data.LAY_TABLE_INDEX][obj.field] = obj.value;
                        }
                    });
                }
            });
        }

        // 初始化编辑弹窗内的班组成员表格
        function initEditTeamMemberTable(teamMembers) {
            // 确保每个成员都有id字段
            var processedMembers = teamMembers.map(function (member) {
                return {
                    id: member.id || 0,
                    accountId: member.accountId || 0,
                    memberName: member.memberName || '',
                    memberRealName: member.memberRealName || '',
                    phone: member.phone || '',
                    createTime: member.createTime || '',
                    creator: member.creator || '',
                    modifyTime: member.modifyTime || '',
                    modifier: member.modifier || '',
                    isDeleted: false // 添加删除标记字段
                };
            });

            layui.table.render({
                elem: '#editModalTeamMemberTable',
                data: processedMembers,
                page: false,
                edit: 'cell', // 启用单元格编辑
                id: 'editModalTeamMemberTable', // 添加唯一标识符
                cols: [[
                    { type: 'checkbox', fixed: 'left' },
                    { field: 'id', title: 'ID', width: 80, hide: true },
                    { field: 'memberName', title: '成员名称', minWidth: 150, edit: 'text' },
                    { field: 'memberRealName', title: '成员姓名', minWidth: 150, edit: 'text' },
                    { field: 'phone', title: '电话号码', minWidth: 150, edit: 'text' }
                ]],
                done: function() {
                    // 监听单元格编辑事件
                    layui.table.on('edit(editModalTeamMemberTable)', function(obj) {
                        console.log('编辑单元格:', obj.field, '新值:', obj.value, '行数据:', obj.data);
                        // 更新缓存中的数据
                        var currentData = layui.table.cache.editModalTeamMemberTable || [];
                        if (currentData[obj.data.LAY_TABLE_INDEX]) {
                            currentData[obj.data.LAY_TABLE_INDEX][obj.field] = obj.value;
                        }
                    });
                }
            });
        }

        // 选择用户
        function selectUser() {
            window.selectUserModalIndex = layui.layer.open({
                type: 1,
                title: '选择用户',
                area: ['1100px', '650px'],
                content: $('#selectUserModal'),
                zIndex: 9999999, // 设置最高层级，确保显示在所有弹框之上
                success: function (layero, index) {
                    // 添加CSS类以确保层级
                    layero.addClass('select-user-layer');

                    // 初始化用户表格
                    initUserTable();

                    // 强制设置层级，确保显示在最上层
                    setTimeout(function () {
                        var layerElement = layero.find('.layui-layer');
                        if (layerElement.length > 0) {
                            layerElement.css('z-index', '9999999 !important');
                            layerElement.css('position', 'fixed');
                        }

                        // 确保遮罩层也在正确层级
                        var maskLayer = $('.layui-layer-shade');
                        if (maskLayer.length > 0) {
                            maskLayer.css('z-index', '9999998 !important');
                        }

                        // 调用确保层级函数
                        ensureSelectUserModalZIndex();
                    }, 100);
                }
            });
        }

        // 初始化用户表格
        function initUserTable() {

            layui.table.render({
                elem: '#userTable',
                url: '/Team/GetAccountForSelection',
                method: 'get',
                page: true,
                limit: 30,
                limits: [10, 20, 30, 50, 100],
                parseData: function (res) {

                    var processedData = processTableData(res.pageData || []);
                    return {
                        "code": res.code === 200 ? 0 : res.code,
                        "msg": res.msg || "",
                        "count": res.totaCount || 0,
                        "data": processedData
                    };
                },
                cols: [[
                    { type: 'checkbox', fixed: 'left' },
                    { field: 'name', title: '账号', minWidth: 150 },
                    { field: 'realName', title: '真实姓名', minWidth: 150 },
                    {
                        field: 'isState', title: '是否启用', minWidth: 100, templet: function (d) {
                            return d.isState ? '是' : '否';
                        }
                    },
                    { field: 'createTime', title: '创建时间', minWidth: 180 }
                ]],
                done: function (res) {

                    // 确保表格层级正确
                    ensureSelectUserModalZIndex();
                }
            });
        }

        // 确保选择用户弹框层级正确
        function ensureSelectUserModalZIndex() {
            setTimeout(function () {
                // 查找选择用户弹框
                var selectUserLayer = $('.layui-layer:has(#selectUserModal)');
                if (selectUserLayer.length > 0) {
                    selectUserLayer.css('z-index', '9999999 !important');
                    selectUserLayer.css('position', 'fixed');
                }

                // 确保遮罩层层级正确
                var maskLayer = $('.layui-layer-shade');
                if (maskLayer.length > 0) {
                    maskLayer.css('z-index', '9999998 !important');
                }

                // 确保弹框内容层级正确
                var modalContent = $('#selectUserModal');
                if (modalContent.length > 0) {
                    modalContent.css('z-index', '9999999 !important');
                    modalContent.css('position', 'relative');
                }

            }, 200);
        }

        // 添加选择的用户到班组成员
        function addSelectedUsers() {
            // 防止重复提交
            var addBtn = $('button[onclick="addSelectedUsers()"]');
            if (addBtn.hasClass('layui-btn-disabled')) {
                return;
            }

            var checkStatus = layui.table.checkStatus('userTable');

            if (checkStatus.data.length === 0) {
                showWarning('请选择用户');
                return;
            }

            // 禁用添加按钮
            addBtn.addClass('layui-btn-disabled').prop('disabled', true);
            addBtn.html('<i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i> 添加中...');

            var teamMemberData = [];
            checkStatus.data.forEach(function (user) {
                teamMemberData.push({
                    id: 0, // 0表示新增
                    accountId: user.id,
                    memberName: user.name,
                    memberRealName: user.realName,
                    phone: ''
                });
            });

            // 判断当前是新建还是编辑弹窗
            if (window.editTeamModalIndex) {
                // 编辑弹窗 - 获取当前数据并合并
                var currentData = layui.table.cache.editModalTeamMemberTable || [];
                // 过滤掉已删除的数据
                currentData = currentData.filter(function(item) {
                    return !item.isDeleted;
                });
                // 合并新数据
                currentData = currentData.concat(teamMemberData);
                layui.table.reload('editModalTeamMemberTable', {
                    data: currentData
                });
            } else if (window.addTeamModalIndex) {
                // 新建弹窗 - 获取当前数据并合并
                var currentData = layui.table.cache.modalTeamMemberTable || [];
                console.log('新建弹窗 - 当前数据:', currentData);
                console.log('要添加的数据:', teamMemberData);
                currentData = currentData.concat(teamMemberData);
                console.log('合并后的数据:', currentData);
                
                // 确保表格存在并重新渲染
                if ($('#modalTeamMemberTable').length > 0) {
                    layui.table.reload('modalTeamMemberTable', {
                        data: currentData
                    });
                } else {
                    // 如果表格不存在，重新初始化
                    initTeamMemberTable();
                    setTimeout(function() {
                        layui.table.reload('modalTeamMemberTable', {
                            data: currentData
                        });
                    }, 100);
                }
            } else {
                // 兜底逻辑 - 尝试检测当前激活的弹窗
                var activeModal = $('.layui-layer:visible');
                console.log('检测到的激活弹窗:', activeModal);
                if (activeModal.find('#editModalTeamMemberTable').length > 0) {
                    // 编辑弹窗
                    var currentData = layui.table.cache.editModalTeamMemberTable || [];
                    currentData = currentData.filter(function(item) {
                        return !item.isDeleted;
                    });
                    currentData = currentData.concat(teamMemberData);
                    layui.table.reload('editModalTeamMemberTable', {
                        data: currentData
                    });
                } else if (activeModal.find('#modalTeamMemberTable').length > 0) {
                    // 新建弹窗
                    var currentData = layui.table.cache.modalTeamMemberTable || [];
                    currentData = currentData.concat(teamMemberData);
                    layui.table.reload('modalTeamMemberTable', {
                        data: currentData
                    });
                } else {
                    console.error('未找到对应的表格容器');
                    showError('无法确定当前弹窗类型，请重试');
                }
            }

            // 只关闭选择用户弹框，保留班组弹框
            if (window.selectUserModalIndex) {
                layui.layer.close(window.selectUserModalIndex);
            }

            // 显示成功提示
            showSuccess('已添加 ' + teamMemberData.length + ' 个用户到班组成员');

            // 恢复添加按钮
            setTimeout(function () {
                addBtn.removeClass('layui-btn-disabled').prop('disabled', false);
                addBtn.html('<i class="layui-icon layui-icon-add-1"></i> 添加选择的数据');
            }, 500);
        }

        // 保存班组
        function saveTeam() {
            // 防止重复提交
            var saveBtn = $('button[onclick="saveTeam()"]');
            if (saveBtn.hasClass('layui-btn-disabled')) {
                return;
            }

            var formData = layui.form.val('addTeamForm');
            var teamMemberData = layui.table.cache.modalTeamMemberTable || [];

            if (!formData.teamName) {
                showWarning('请输入班组名称');
                return;
            }

            // 禁用保存按钮
            saveBtn.addClass('layui-btn-disabled').prop('disabled', true);
            saveBtn.html('<i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i> 保存中...');

            var teamData = {
                teamName: formData.teamName,
                teamCode: formData.teamCode,
                teamType: parseInt(formData.teamType) || 0,
                remark: formData.remark,
                teamMembers: teamMemberData
            };

            $.ajax({
                url: '/Team/AddTeam',
                method: 'POST',
                contentType: 'application/json',
                data: JSON.stringify(teamData),
                success: function (res) {
                    if (res.code === 200) {
                        showSuccess('添加班组成功');
                        // 关闭班组新建弹框
                        if (window.addTeamModalIndex) {
                            layui.layer.close(window.addTeamModalIndex);
                        }
                        // 刷新班组表格
                        teamTable.reload();
                    } else {
                        showError(res.msg || '添加班组失败');
                        // 恢复保存按钮
                        saveBtn.removeClass('layui-btn-disabled').prop('disabled', false);
                        saveBtn.html('<i class="layui-icon layui-icon-ok"></i> 保存');
                    }
                },
                error: function () {
                    showError('添加班组失败');
                    // 恢复保存按钮
                    saveBtn.removeClass('layui-btn-disabled').prop('disabled', false);
                    saveBtn.html('<i class="layui-icon layui-icon-ok"></i> 保存');
                },
                complete: function () {
                    // 确保按钮状态恢复
                    saveBtn.removeClass('layui-btn-disabled').prop('disabled', false);
                    saveBtn.html('<i class="layui-icon layui-icon-ok"></i> 保存');
                }
            });
        }

        // 保存编辑班组
        function saveEditTeam() {
            // 防止重复提交
            var saveBtn = $('button[onclick="saveEditTeam()"]');
            if (saveBtn.hasClass('layui-btn-disabled')) {
                return;
            }

            var formData = layui.form.val('editTeamForm');
            var teamMemberData = layui.table.cache.editModalTeamMemberTable || [];

            console.log('保存编辑班组 - 原始成员数据:', teamMemberData);

            if (!formData.teamName) {
                showWarning('请输入班组名称');
                return;
            }

            // 处理班组成员数据 - 过滤掉已删除的数据
            var processedTeamMembers = teamMemberData.filter(function(item) {
                return !item.isDeleted;
            });

            console.log('保存编辑班组 - 处理后的成员数据:', processedTeamMembers);

            // 禁用保存按钮
            saveBtn.addClass('layui-btn-disabled').prop('disabled', true);
            saveBtn.html('<i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i> 保存中...');

            var teamData = {
                teamId: parseInt(formData.teamId),
                teamName: formData.teamName,
                teamCode: formData.teamCode,
                teamType: parseInt(formData.teamType) || 0,
                remark: formData.remark,
                teamMembers: processedTeamMembers
            };

            $.ajax({
                url: '/Team/UpdateTeam',
                method: 'POST',
                contentType: 'application/json',
                data: JSON.stringify(teamData),
                success: function (res) {
                    if (res.code === 200) {
                        showSuccess('编辑班组成功');
                        // 关闭班组编辑弹框
                        if (window.editTeamModalIndex) {
                            layui.layer.close(window.editTeamModalIndex);
                        }
                        // 刷新班组表格
                        teamTable.reload();
                    } else {
                        showError(res.msg || '编辑班组失败');
                        // 恢复保存按钮
                        saveBtn.removeClass('layui-btn-disabled').prop('disabled', false);
                        saveBtn.html('<i class="layui-icon layui-icon-ok"></i> 保存');
                    }
                },
                error: function () {
                    showError('编辑班组失败');
                    // 恢复保存按钮
                    saveBtn.removeClass('layui-btn-disabled').prop('disabled', false);
                    saveBtn.html('<i class="layui-icon layui-icon-ok"></i> 保存');
                },
                complete: function () {
                    // 确保按钮状态恢复
                    saveBtn.removeClass('layui-btn-disabled').prop('disabled', false);
                    saveBtn.html('<i class="layui-icon layui-icon-ok"></i> 保存');
                }
            });
        }



        // 添加行
        function addRow() {
            var currentData = layui.table.cache.modalTeamMemberTable || [];
            currentData.push({
                memberName: '',
                memberRealName: '',
                phone: ''
            });
            layui.table.reload('modalTeamMemberTable', {
                data: currentData
            });

            // 确保表格自适应
            setTimeout(function () {
                ensureTableResponsive();
            }, 100);
        }

        // 删除行
        function deleteRow() {
            var checkStatus = layui.table.checkStatus('modalTeamMemberTable');
            if (checkStatus.data.length === 0) {
                showWarning('请选择要删除的行');
                return;
            }

            // 确认删除
            layui.layer.confirm('确定要删除选中的 ' + checkStatus.data.length + ' 行数据吗？', {
                icon: 3,
                title: '确认删除'
            }, function (index) {
                var currentData = layui.table.cache.modalTeamMemberTable || [];
                
                console.log('当前表格数据:', currentData);
                console.log('选中的数据:', checkStatus.data);
                
                // 使用更可靠的方法获取选中行的索引
                var selectedIndexes = [];
                checkStatus.data.forEach(function(selectedItem) {
                    // 通过数据内容匹配来找到索引
                    for (var i = 0; i < currentData.length; i++) {
                        var currentItem = currentData[i];
                        // 通过成员名称和真实姓名来匹配
                        if (currentItem.memberName === selectedItem.memberName && 
                            currentItem.memberRealName === selectedItem.memberRealName) {
                            selectedIndexes.push(i);
                            break;
                        }
                    }
                });

                console.log('找到的索引:', selectedIndexes);

                // 从大到小排序，从后往前删除
                selectedIndexes.sort(function (a, b) { return b - a; });

                selectedIndexes.forEach(function (rowIndex) {
                    if (currentData[rowIndex]) {
                        console.log('删除索引:', rowIndex, '数据:', currentData[rowIndex]);
                        currentData.splice(rowIndex, 1);
                    }
                });

                console.log('删除后的数据:', currentData);

                // 重新渲染表格
                layui.table.reload('modalTeamMemberTable', {
                    data: currentData
                });

                layui.layer.close(index);
                showSuccess('删除成功');
            });
        }

        // 编辑班组
        function editTeam() {
            var checkStatus = layui.table.checkStatus('teamTable');
            if (checkStatus.data.length === 0) {
                showError('请选择要编辑的班组');
                return;
            }

            if (checkStatus.data.length > 1) {
                showError('只能选择一个班组进行编辑');
                return;
            }

            var teamData = checkStatus.data[0];
            showEditTeamModal(teamData);
        }

        // 删除班组
        function deleteTeam() {
            var checkStatus = layui.table.checkStatus('teamTable');
            if (checkStatus.data.length === 0) {
                showError('请选择要删除的班组');
                return;
            }

            var teamIds = checkStatus.data.map(function (item) {
                return item.id;
            });

            layer.confirm('确定要删除选中的 ' + teamIds.length + ' 个班组吗？', {
                icon: 3,
                title: '确认删除'
            }, function (index) {
                // 防止重复提交
                var deleteBtn = $('button[onclick="deleteTeam()"]');
                if (deleteBtn.hasClass('layui-btn-disabled')) {
                    return;
                }

                // 禁用删除按钮
                deleteBtn.addClass('layui-btn-disabled').prop('disabled', true);
                deleteBtn.html('<i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i> 删除中...');

                $.ajax({
                    url: '/Team/DeleteTeam',
                    method: 'POST',
                    contentType: 'application/json',
                    data: JSON.stringify({ teamIds: teamIds }),
                    success: function (res) {
                        if (res.code === 200) {
                            showSuccess('删除成功');
                            // 刷新班组表格
                            teamTable.reload();
                            // 清空班组成员表格
                            layui.table.reload('teamMemberTable', {
                                data: []
                            });
                        } else {
                            showError(res.msg || '删除失败');
                        }
                    },
                    error: function (xhr, status, error) {

                        var errorMsg = '删除失败，请稍后重试';
                        try {
                            var response = JSON.parse(xhr.responseText);
                            errorMsg = response.message || response.msg || errorMsg;
                        } catch (e) {
                            // 解析失败，使用默认错误信息
                        }
                        showError(errorMsg);
                    },
                    complete: function () {
                        // 恢复删除按钮
                        deleteBtn.removeClass('layui-btn-disabled').prop('disabled', false);
                        deleteBtn.html('<i class="layui-icon layui-icon-delete"></i> 删除');
                        layer.close(index);
                    }
                });
            });
        }

        // 导入班组
        function importTeam() {
            selectedFile = null;
            $('#fileList').empty();
            
            layui.layer.open({
                type: 1,
                title: false,
                closeBtn: 1,
                shade: 0.3,
                shadeClose: false,
                area: ['600px', '500px'],
                content: $('#importModal'),
                success: function (layero, index) {
                    importLayerIndex = index;
                    applyModalBeautification();
                    ensureModalZIndex();
                }
            });
        }

        // 导出班组
        function exportTeam() {
            showWarning('导出班组功能待实现');
        }

        // 关闭班组新建弹框
        function closeAddTeamModal() {
            if (window.addTeamModalIndex) {
                layui.layer.close(window.addTeamModalIndex);
            }
        }

        // 关闭选择用户弹框
        function closeSelectUserModal() {
            if (window.selectUserModalIndex) {
                layui.layer.close(window.selectUserModalIndex);
            }
        }

        // 关闭编辑班组弹框
        function closeEditTeamModal() {
            if (window.editTeamModalIndex) {
                layui.layer.close(window.editTeamModalIndex);
            }
        }

        // 为编辑弹窗选择用户
        function selectUserForEdit() {
            window.selectUserModalIndex = layui.layer.open({
                type: 1,
                title: '选择用户',
                area: ['1100px', '650px'],
                content: $('#selectUserModal'),
                zIndex: 9999999, // 设置最高层级，确保显示在所有弹框之上
                success: function (layero, index) {
                    // 添加CSS类以确保层级
                    layero.addClass('select-user-layer');

                    // 初始化用户表格
                    initUserTable();

                    // 强制设置层级，确保显示在最上层
                    setTimeout(function () {
                        var layerElement = layero.find('.layui-layer');
                        if (layerElement.length > 0) {
                            layerElement.css('z-index', '9999999 !important');
                            layerElement.css('position', 'fixed');
                        }

                        // 确保遮罩层也在正确层级
                        var maskElement = $('.layui-layer-shade');
                        if (maskElement.length > 0) {
                            maskElement.css('z-index', '9999998 !important');
                        }

                        // 调用确保层级函数
                        ensureSelectUserModalZIndex();
                    }, 100);
                }
            });
        }

        // 为编辑弹窗添加行
        function addRowForEdit() {
            var currentData = layui.table.cache.editModalTeamMemberTable || [];
            currentData.push({
                id: 0, // 0表示新增
                memberName: '',
                memberRealName: '',
                phone: ''
            });
            layui.table.reload('editModalTeamMemberTable', {
                data: currentData
            });

            // 确保表格自适应
            setTimeout(function () {
                ensureTableResponsive();
            }, 100);
        }

        // 确保表格响应式
        function ensureTableResponsive() {
            // 重新计算表格宽度
            var tableContainer = $('.table-container');
            var table = tableContainer.find('.layui-table');

            if (table.length > 0) {
                table.css('width', '100%');
                tableContainer.css('overflow-x', 'hidden');

                // 强制重新渲染表格
                layui.table.render();
            }
        }

        // 时间格式化函数
        function formatDateTime(dateTimeStr) {


            if (!dateTimeStr || dateTimeStr === '' || dateTimeStr === null || dateTimeStr === undefined) {

                return '-';
            }

            try {
                // 如果是已经是格式化好的时间字符串，直接返回
                if (typeof dateTimeStr === 'string' && dateTimeStr.match(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/)) {
    
                    return dateTimeStr;
                }

                var date = new Date(dateTimeStr);


                if (isNaN(date.getTime())) {

                    return '-';
                }

                var year = date.getFullYear();
                var month = (date.getMonth() + 1).toString().padStart(2, '0');
                var day = date.getDate().toString().padStart(2, '0');
                var hours = date.getHours().toString().padStart(2, '0');
                var minutes = date.getMinutes().toString().padStart(2, '0');
                var seconds = date.getSeconds().toString().padStart(2, '0');

                var formattedTime = year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;

                return formattedTime;
            } catch (e) {

                return '-';
            }
        }

        // 处理表格数据中的时间字段
        function processTableData(data) {


            if (!data || !Array.isArray(data)) {

                return data;
            }

            return data.map(function (item, index) {


                if (item.createTime !== undefined && item.createTime !== null) {

                    item.createTime = formatDateTime(item.createTime);
                }
                if (item.modifyTime !== undefined && item.modifyTime !== null) {

                    item.modifyTime = formatDateTime(item.modifyTime);
                }


                return item;
            });
        }

        // 为编辑弹窗删除行
        function deleteRowForEdit() {
            var checkStatus = layui.table.checkStatus('editModalTeamMemberTable');

            if (checkStatus.data.length === 0) {
                showWarning('请选择要删除的行');
                return;
            }

            // 确认删除
            layui.layer.confirm('确定要删除选中的 ' + checkStatus.data.length + ' 行数据吗？', {
                icon: 3,
                title: '确认删除'
            }, function (index) {
                var currentData = layui.table.cache.editModalTeamMemberTable || [];

                console.log('编辑弹窗 - 当前表格数据:', currentData);
                console.log('编辑弹窗 - 选中的数据:', checkStatus.data);
                
                // 使用更可靠的方法获取选中行的索引
                var selectedIndexes = [];
                checkStatus.data.forEach(function(selectedItem) {
                    // 通过数据内容匹配来找到索引
                    for (var i = 0; i < currentData.length; i++) {
                        var currentItem = currentData[i];
                        // 通过成员名称和真实姓名来匹配
                        if (currentItem.memberName === selectedItem.memberName && 
                            currentItem.memberRealName === selectedItem.memberRealName) {
                            selectedIndexes.push(i);
                            break;
                        }
                    }
                });

                console.log('编辑弹窗 - 找到的索引:', selectedIndexes);

                // 从大到小排序，从后往前删除
                selectedIndexes.sort(function (a, b) { return b - a; });

                selectedIndexes.forEach(function (rowIndex) {
                    if (currentData[rowIndex]) {
                        console.log('编辑弹窗 - 删除索引:', rowIndex, '数据:', currentData[rowIndex]);
                        // 如果是有ID的现有数据，标记为删除
                        if (currentData[rowIndex].id && currentData[rowIndex].id > 0) {
                            currentData[rowIndex].isDeleted = true;
                        } else {
                            // 直接删除新增的行
                            currentData.splice(rowIndex, 1);
                        }
                    }
                });

                console.log('编辑弹窗 - 删除后的数据:', currentData);

                // 过滤掉已删除的数据用于显示
                var displayData = currentData.filter(function(item) {
                    return !item.isDeleted;
                });

                console.log('编辑弹窗 - 显示数据:', displayData);

                // 重新渲染表格
                layui.table.reload('editModalTeamMemberTable', {
                    data: displayData
                });

                layui.layer.close(index);
                showSuccess('删除成功');
            });
        }

        // 编辑班组成员
        function editTeamMember(data) {
            showWarning('编辑班组成员功能待实现');
        }

        // 删除班组成员
        function deleteTeamMember(data) {
            showWarning('删除班组成员功能待实现');
        }

        // 页面加载完成后确保层级设置正确
        $(document).ready(function () {
            // 加载保存的列设置
            loadSavedColumnSettings();

            // 监听弹框打开事件
            $(document).on('DOMNodeInserted', function (e) {
                if ($(e.target).hasClass('layui-layer') && $(e.target).find('#selectUserModal').length > 0) {
                    setTimeout(function () {
                        ensureSelectUserModalZIndex();
                    }, 100);
                }

                // 监听所有弹框打开事件
                if ($(e.target).hasClass('layui-layer')) {
                    setTimeout(function () {
                        ensureModalZIndex();
                    }, 100);
                }
            });

            // 应用弹框美化效果
            applyModalBeautification();
        });

        // 应用弹框美化效果
        function applyModalBeautification() {
            // 为所有弹框添加美化类
            $('.layui-layer').addClass('beautified-modal');

            // 确保表单渲染正确
            layui.form.render();

            // 为表格添加美化效果
            $('.layui-table').addClass('beautified-table');


        }

        // 确保弹框层级正确
        function ensureModalZIndex() {
            // 设置弹框层级
            $('.layui-layer').css('z-index', '99999');

            // 设置遮罩层层级
            $('.layui-layer-shade').css('z-index', '99998');

            // 确保主页面元素层级较低
            $('.layui-fluid, .layui-card, .search-area, .search-buttons').css('z-index', '1');


        }

        // 获取表格列配置
        function getTableColumns() {
            var cols = [
                { type: 'checkbox', fixed: 'left' }
            ];

            // 按顺序添加可见的列
            var sortedFields = Object.keys(columnSettings).sort(function (a, b) {
                return columnSettings[a].order - columnSettings[b].order;
            });

            sortedFields.forEach(function (field) {
                if (columnSettings[field].visible && columnConfigs[field]) {
                    cols.push(columnConfigs[field]);
                }
            });

            return cols;
        }

        // 显示列设置弹窗
        function showColumnSettings() {

            updateCheckboxStates();
            updateColumnOrder();

            layui.layer.open({
                type: 1,
                title: false,
                closeBtn: 1,
                shade: 0,
                shadeClose: false,
                area: ['500px', '450px'],
                content: $('#columnSettingsModal'),
                success: function (layero, index) {
    
                    layui.form.render();
                    bindColumnSettingsEvents(index);

                    // 延迟初始化拖拽功能，确保DOM完全渲染
                    setTimeout(function () {
                        initDragAndDrop();
                    }, 100);
                }
            });
        }

        // 更新复选框状态
        function updateCheckboxStates() {
            $('#columnSettingsTable input[type="checkbox"]').each(function () {
                var field = $(this).attr('name');
                $(this).prop('checked', columnSettings[field].visible);
            });
        }

        // 更新列顺序显示
        function updateColumnOrder() {
            var sortedFields = Object.keys(columnSettings).sort(function (a, b) {
                return columnSettings[a].order - columnSettings[b].order;
            });

            var tbody = $('#columnSettingsBody');
            tbody.empty();

            sortedFields.forEach(function (field, index) {
                var setting = columnSettings[field];
                var row = `
                                                                            <tr data-field="${field}" class="draggable-row">
                                                                                <td>${index + 1}</td>
                                                                                <td class="drag-handle" style="cursor: move;">
                                                                                    <i class="layui-icon layui-icon-drag" style="margin-right: 8px; color: #999;"></i>
                                                                                    ${getColumnTitle(field)}
                                                                                </td>
                                                                                <td><input type="checkbox" name="${field}" lay-skin="primary" title="显示" ${setting.visible ? 'checked' : ''}></td>
                                                                            </tr>
                                                                        `;
                tbody.append(row);
            });
        }

        // 获取列标题
        function getColumnTitle(field) {
            var titles = {
                'teamName': '班组名称',
                'teamCode': '编组编码',
                'teamType': '班组类型',
                'remark': '备注',
                'creator': '创建人',
                'createTime': '创建时间',
                'modifier': '修改人',
                'modifyTime': '修改时间'
            };
            return titles[field] || field;
        }

        // 初始化拖拽功能
        function initDragAndDrop() {
            try {
                // 检查jQuery UI是否可用
                if (typeof $.fn.sortable === 'undefined') {
    
                    // 如果没有jQuery UI，使用简单的拖拽提示
                    $('.drag-handle').css('cursor', 'default');
                    $('.drag-handle i').removeClass('layui-icon-drag').addClass('layui-icon-more-vertical');
                    return;
                }

                $('#columnSettingsBody').sortable({
                    handle: '.drag-handle',
                    axis: 'y',
                    opacity: 0.8,
                    tolerance: 'pointer',
                    cursor: 'move',
                    placeholder: 'ui-state-highlight',
                    helper: function (e, tr) {
                        var $originals = tr.children();
                        var $helper = tr.clone();
                        $helper.children().each(function (index) {
                            $(this).width($originals.eq(index).width());
                        });
                        return $helper;
                    },
                    start: function (event, ui) {
                        ui.item.addClass('dragging');
                        ui.placeholder.height(ui.item.height());
                    },
                    stop: function (event, ui) {
                        ui.item.removeClass('dragging');
                    },
                    update: function (event, ui) {
                        updateColumnOrderAfterDrag();
                    }
                });


            } catch (error) {

                // 降级处理：显示提示信息
                $('.drag-handle').css('cursor', 'default');
                $('.drag-handle i').removeClass('layui-icon-drag').addClass('layui-icon-more-vertical');
                showWarning('拖拽功能初始化失败，请刷新页面重试');
            }
        }

        // 拖拽后更新列顺序
        function updateColumnOrderAfterDrag() {

            $('#columnSettingsBody tr').each(function (index) {
                var field = $(this).data('field');
                if (field && columnSettings[field]) {
                    columnSettings[field].order = index + 1;
    
                }
                $(this).find('td:first').text(index + 1);
            });

            // 显示提示信息
            showSuccess('列顺序已调整');
        }

        // 绑定列设置事件
        function bindColumnSettingsEvents(layerIndex) {
            $('#cancelColumnSettings').off('click').on('click', function () {
                layui.layer.close(layerIndex);
            });

            $('#resetColumnSettings').off('click').on('click', function () {
                columnSettings = {
                    teamName: { visible: true, order: 1 },
                    teamCode: { visible: true, order: 2 },
                    teamType: { visible: true, order: 3 },
                    remark: { visible: true, order: 4 },
                    creator: { visible: true, order: 5 },
                    createTime: { visible: true, order: 6 },
                    modifier: { visible: true, order: 7 },
                    modifyTime: { visible: true, order: 8 }
                };
                updateCheckboxStates();
                updateColumnOrder();
                layui.form.render();
            });

            $('#confirmColumnSettings').off('click').on('click', function () {
                // 更新可见性设置
                $('#columnSettingsTable input[type="checkbox"]').each(function () {
                    var field = $(this).attr('name');
                    if (columnSettings[field]) {
                        columnSettings[field].visible = $(this).prop('checked');
                    }
                });

                // 保存设置到localStorage
                localStorage.setItem('teamColumnSettings', JSON.stringify(columnSettings));

                reloadTableWithColumnSettings();
                layui.layer.close(layerIndex);
                showSuccess('列设置已更新');
            });
        }

        // 根据列设置重新渲染表格
        function reloadTableWithColumnSettings() {
            layui.table.reload('teamTable', {
                cols: [getTableColumns()]
            });
        }

        // 加载保存的列设置
        function loadSavedColumnSettings() {
            var savedSettings = localStorage.getItem('teamColumnSettings');
            if (savedSettings) {
                try {
                    var saved = JSON.parse(savedSettings);
                    // 合并保存的设置，保持默认值作为后备
                    Object.keys(saved).forEach(function (field) {
                        if (columnSettings[field]) {
                            columnSettings[field].visible = saved[field].visible !== undefined ? saved[field].visible : columnSettings[field].visible;
                            columnSettings[field].order = saved[field].order !== undefined ? saved[field].order : columnSettings[field].order;
                        }
                    });
                } catch (error) {
        
                }
            }
        }

        // ==================== 导入导出功能 ====================

        // 全局变量
        var selectedFile = null;
        var importLayerIndex = null;

        // 显示加载中
        function showLoading() {
            layui.layer.load(1, {
                shade: [0.3, '#000']
            });
        }

        // 隐藏加载中
        function hideLoading() {
            layui.layer.closeAll('loading');
        }

        // 导入班组
        function importTeam() {
            selectedFile = null;
            $('#fileList').empty();
            
            layui.layer.open({
                type: 1,
                title: false,
                closeBtn: 1,
                shade: 0.3,
                shadeClose: false,
                area: ['600px', '500px'],
                content: $('#importModal'),
                success: function (layero, index) {
                    importLayerIndex = index;
                    applyModalBeautification();
                    ensureModalZIndex();
                }
            });
        }

        // 导出班组
        function exportTeam() {
            showLoading();
            
            // 获取当前查询条件
            var teamName = $('#teamName').val();
            var teamCode = $('#teamCode').val();
            var teamType = $('#teamType').val();
            
            // 构建导出URL
            var url = '/Team/ExportTeams?';
            var params = [];
            if (teamName) params.push('teamName=' + encodeURIComponent(teamName));
            if (teamCode) params.push('teamCode=' + encodeURIComponent(teamCode));
            if (teamType) params.push('teamType=' + encodeURIComponent(teamType));
            
            url += params.join('&');
            
            // 创建下载链接
            var link = document.createElement('a');
            link.href = url;
            link.download = '班组数据_' + new Date().toISOString().slice(0, 19).replace(/:/g, '-') + '.xlsx';
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
            
            hideLoading();
            showSuccess('导出成功');
        }

        // 下载模板
        function downloadTemplate() {
            showLoading();
            
            var link = document.createElement('a');
            link.href = '/Team/DownloadTemplate';
            link.download = '班组导入模板.xlsx';
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
            
            hideLoading();
            showSuccess('模板下载成功');
        }

        // 选择文件
        function selectFile() {
            var input = document.createElement('input');
            input.type = 'file';
            input.accept = '.xlsx';
            input.onchange = function (e) {
                var file = e.target.files[0];
                if (file) {
                    handleFileSelect(file);
                }
            };
            input.click();
        }

        // 处理文件选择
        function handleFileSelect(file) {
            // 验证文件类型
            if (!file.name.endsWith('.xlsx')) {
                showError('请选择.xlsx格式的Excel文件');
                return;
            }

            // 验证文件大小（100MB）
            if (file.size > 100 * 1024 * 1024) {
                showError('文件大小不能超过100MB');
                return;
            }

            selectedFile = file;
            displaySelectedFile(file);
        }

        // 显示选中的文件
        function displaySelectedFile(file) {
            var fileSize = formatFileSize(file.size);
            var fileHtml = `
                <div class="file-item">
                    <div class="file-info">
                        <i class="layui-icon layui-icon-file file-icon"></i>
                        <span class="file-name">${file.name}</span>
                        <span class="file-size">${fileSize}</span>
                    </div>
                    <i class="layui-icon layui-icon-close file-remove" onclick="removeSelectedFile()"></i>
                </div>
            `;
            $('#fileList').html(fileHtml);
        }

        // 移除选中的文件
        function removeSelectedFile() {
            selectedFile = null;
            $('#fileList').empty();
        }

        // 格式化文件大小
        function formatFileSize(bytes) {
            if (bytes === 0) return '0 Bytes';
            var k = 1024;
            var sizes = ['Bytes', 'KB', 'MB', 'GB'];
            var i = Math.floor(Math.log(bytes) / Math.log(k));
            return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
        }

        // 上传文件
        function uploadFile() {
            if (!selectedFile) {
                showError('请先选择要上传的文件');
                return;
            }

            var formData = new FormData();
            formData.append('file', selectedFile);

            // 显示进度条
            showUploadProgress();

            $.ajax({
                url: '/Team/ImportTeams',
                type: 'POST',
                data: formData,
                processData: false,
                contentType: false,
                xhr: function () {
                    var xhr = new window.XMLHttpRequest();
                    xhr.upload.addEventListener('progress', function (evt) {
                        if (evt.lengthComputable) {
                            var percentComplete = evt.loaded / evt.total;
                            updateProgress(percentComplete * 100);
                        }
                    }, false);
                    return xhr;
                },
                success: function (response) {
                    hideUploadProgress();
                    if (response.success) {
                        showSuccess(response.message);
                        closeImportModal();
                        // 刷新表格
                        teamTable.reload();
                    } else {
                        showError(response.message);
                        if (response.errors && response.errors.length > 0) {
                            displayImportErrors(response.errors);
                        }
                    }
                },
                error: function (xhr, status, error) {
                    hideUploadProgress();

                    var errorMsg = '上传失败，请稍后重试';
                    try {
                        var response = JSON.parse(xhr.responseText);
                        errorMsg = response.message || response.msg || errorMsg;
                    } catch (e) {
                        // 解析失败，使用默认错误信息
                    }
                    showError(errorMsg);
                }
            });
        }

        // 显示上传进度
        function showUploadProgress() {
            $('.upload-progress').show();
            updateProgress(0);
        }

        // 隐藏上传进度
        function hideUploadProgress() {
            $('.upload-progress').hide();
        }

        // 更新进度条
        function updateProgress(percent) {
            $('.progress-fill').css('width', percent + '%');
            $('.progress-text').text('上传进度: ' + Math.round(percent) + '%');
        }

        // 显示导入错误
        function displayImportErrors(errors) {
            var errorHtml = '<div class="error-list" style="margin-top: 15px; max-height: 200px; overflow-y: auto;">';
            errorHtml += '<h4 style="color: #dc3545; margin-bottom: 10px;">导入错误详情:</h4>';
            errors.forEach(function (error) {
                errorHtml += '<div style="color: #dc3545; margin-bottom: 5px; font-size: 12px;">• ' + error + '</div>';
            });
            errorHtml += '</div>';
            
            $('#fileList').append(errorHtml);
        }

        // 关闭导入弹框
        function closeImportModal() {
            if (importLayerIndex !== null) {
                layui.layer.close(importLayerIndex);
                importLayerIndex = null;
            }
            selectedFile = null;
            $('#fileList').empty();
        }
    </script>
}

<!-- 添加班组弹窗 -->
<div id="addTeamModal" style="display: none;">
    <div class="form-section">
        <div class="modal-section-title">
            <i class="layui-icon layui-icon-edit" style="margin-right: 8px; color: #667eea;"></i>
            基本信息
        </div>
    <form class="layui-form" lay-filter="addTeamForm">
        <div class="layui-form-item">
                <label class="layui-form-label required-field">班组名称:</label>
            <div class="layui-input-block">
                    <input type="text" name="teamName" placeholder="请输入班组名称" class="layui-input" lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">编组编码:</label>
            <div class="layui-input-block">
                    <input type="text" name="teamCode" placeholder="请输入编组编码，忽略将自动生成" class="layui-input">
                    <div class="modal-tip">
                        <i class="layui-icon layui-icon-tips"></i>
                        如果不填写编组编码，系统将自动生成
                    </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">班组类型:</label>
            <div class="layui-input-block">
                <select name="teamType" class="layui-select">
                    <option value="0">仓库</option>
                    <option value="1">组装</option>
                    <option value="2">机加工</option>
                    <option value="3">注塑</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">备注:</label>
            <div class="layui-input-block">
                    <textarea name="remark" placeholder="请输入备注信息" class="layui-textarea"></textarea>
            </div>
        </div>
    </form>
    </div>

    <div class="section-divider"></div>

    <div class="form-section team-member-section">
        <div class="modal-section-title">
            <i class="layui-icon layui-icon-user" style="margin-right: 8px; color: #667eea;"></i>
            班组成员管理
        </div>
        <div class="modal-button-group">
            <button type="button" class="layui-btn layui-btn-normal" onclick="selectUser()">
                <i class="layui-icon layui-icon-user"></i> 选择用户
            </button>
            <button type="button" class="layui-btn layui-btn-primary" onclick="addRow()">
                <i class="layui-icon layui-icon-add-1"></i> 添加行
            </button>
            <button type="button" class="layui-btn layui-btn-danger" onclick="deleteRow()">
                <i class="layui-icon layui-icon-delete"></i> 删除行
            </button>
        </div>
        <div class="table-container">
        <table id="modalTeamMemberTable" lay-filter="modalTeamMemberTable"></table>
        </div>
    </div>

    <div class="modal-footer">
        <button type="button" class="layui-btn layui-btn-danger" onclick="saveTeam()">
            <i class="layui-icon layui-icon-ok"></i> 保存
        </button>
        <button type="button" class="layui-btn layui-btn-primary" onclick="closeAddTeamModal()">
            <i class="layui-icon layui-icon-close"></i> 关闭
        </button>
    </div>
</div>

<!-- 选择用户弹窗 -->
<div id="selectUserModal" style="display: none;">
    <div style="margin-bottom: 20px;">
        <h4 style="color: #333; font-weight: 600; margin: 0; font-size: 16px;">
            <i class="layui-icon layui-icon-user" style="margin-right: 8px; color: #667eea;"></i>
            请选择要添加的用户
        </h4>
        <p style="color: #666; margin: 5px 0 0 0; font-size: 14px;">支持多选，请勾选需要添加的用户</p>
    </div>
    <table id="userTable" lay-filter="userTable"></table>

    <div class="modal-footer">
        <button type="button" class="layui-btn layui-btn-normal" onclick="addSelectedUsers()">
            <i class="layui-icon layui-icon-add-1"></i> 添加选择的数据
        </button>
        <button type="button" class="layui-btn layui-btn-primary" onclick="closeSelectUserModal()">
            <i class="layui-icon layui-icon-close"></i> 关闭
        </button>
    </div>
</div>

<!-- 编辑班组弹窗 -->
<div id="editTeamModal" style="display: none;">
    <div class="form-section">
        <div class="modal-section-title">
            <i class="layui-icon layui-icon-edit" style="margin-right: 8px; color: #667eea;"></i>
            基本信息
        </div>
    <form class="layui-form" lay-filter="editTeamForm">
        <input type="hidden" name="teamId" value="">
        <div class="layui-form-item">
                <label class="layui-form-label required-field">班组名称:</label>
            <div class="layui-input-block">
                    <input type="text" name="teamName" placeholder="请输入班组名称" class="layui-input" lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">编组编码:</label>
            <div class="layui-input-block">
                <input type="text" name="teamCode" placeholder="编组编码" class="layui-input" readonly>
                    <div class="modal-tip">
                        <i class="layui-icon layui-icon-tips"></i>
                        编组编码创建后不可修改
                    </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">班组类型:</label>
            <div class="layui-input-block">
                <select name="teamType" class="layui-select">
                    <option value="0">仓库</option>
                    <option value="1">组装</option>
                    <option value="2">机加工</option>
                    <option value="3">注塑</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">备注:</label>
            <div class="layui-input-block">
                    <textarea name="remark" placeholder="请输入备注信息" class="layui-textarea"></textarea>
            </div>
        </div>
    </form>
    </div>

    <div class="section-divider"></div>

    <div class="form-section team-member-section">
        <div class="modal-section-title">
            <i class="layui-icon layui-icon-user" style="margin-right: 8px; color: #667eea;"></i>
            班组成员管理
        </div>
        <div class="modal-button-group">
            <button type="button" class="layui-btn layui-btn-normal" onclick="selectUserForEdit()">
                <i class="layui-icon layui-icon-user"></i> 选择用户
            </button>
            <button type="button" class="layui-btn layui-btn-primary" onclick="addRowForEdit()">
                <i class="layui-icon layui-icon-add-1"></i> 添加行
            </button>
            <button type="button" class="layui-btn layui-btn-danger" onclick="deleteRowForEdit()">
                <i class="layui-icon layui-icon-delete"></i> 删除行
            </button>
        </div>
        <div class="table-container">
        <table id="editModalTeamMemberTable" lay-filter="editModalTeamMemberTable"></table>
        </div>
    </div>

    <div class="modal-footer">
        <button type="button" class="layui-btn layui-btn-danger" onclick="saveEditTeam()">
            <i class="layui-icon layui-icon-ok"></i> 保存
        </button>
        <button type="button" class="layui-btn layui-btn-primary" onclick="closeEditTeamModal()">
            <i class="layui-icon layui-icon-close"></i> 关闭
        </button>
    </div>
</div>

